📜  C# 模型中的实体保存示例首先 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:51.105000             🧑  作者: Mango

代码示例3
// disconnected new entity 
var student = new Student(){ StudentName = "Bill" };

using (var context = new SchoolDBEntities())
{
    context.Entry(student).State = student.StudentId == 0? EntityState.Added : EntityState.Modified;

    context.SaveChanges();
}