我正在使用一个MVC示例,其中ID是数据库中的增量。要创建记录,它就像:但在我的情况下,Student表中的ID不是增量的,我需要从Student表中获取MAX(ID)。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,LastName,FirstMidName,EnrollmentDate,CountryID,Account_Code")] Student student)
{
if (ModelState.IsValid)
{
db.Students.Add(student);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(student);
}
我想从我的Include中删除“ID”,并希望从Student表中通过LINQ获取MAX(ID)并将其保存到表中。请帮我谢谢。请有人帮我这个