使用带有 lambda 表达式的 linQ 删除记录

Delete record using linQ with lambda Expression

我想使用 linq lambda 表达式删除 sql 数据库的记录。我该怎么办?

这里 'student' 是我的 table 而 'db' 是 .edmx 文件的对象

public bool DeleteRecord(int caurseID)
{
    studentEntities db = new studentEntities();

    int count = db.student.Where(s => s.caurse_id == caurseID).Count();

    if (count != 0)
    {
        //string subQuery = "delete from student where caurse_id=" + caurseID;
        //SqlCommand subCmd = new SqlCommand(subQuery, conn);
        //subCmd.ExecuteNonQuery();
        db.student. : For Delete, what will be goes here???
    }

    return true;
}
public bool DeleteRecord(int caurseID)
{
   studentEntities db = new studentEntities();

   var students = db.student.Where(s => s.caurse_id == caurseID);


   if(students.Any()) 
   {
       db.DeleteAllOnSubmit(students);

       db.SubmitChanges();
   }

   return true;
}

我参考了之前的建议。

studentEntities db_dlt = new studentEntities();
                var students = db_dlt.student.FirstOrDefault(s => s.caurse_id == caurseID);
                if (students != null)
                {
                    db_dlt.student.Remove(students);
                    db_dlt.SaveChanges();
                }