📅  最后修改于: 2022-03-11 14:48:51.105000             🧑  作者: Mango
// 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();
}