如何从学生获得Max(ID)和在MVC中创建

时间:2015-07-02 06:38:04

标签: asp.net-mvc-3 asp.net-mvc-4 linq-to-entities

我正在使用一个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)并将其保存到表中。请帮我谢谢。请有人帮我这个

0 个答案:

没有答案