Dbcontext 有Entry方法 用他来改变集合里面每一项的状态
//增 不推荐
PeopleEntities context = new PeopleEntities();
//context.Entry<Student>(new Student() { Name = "heyuke", Age = 18 }).State = EntityState.Added;
//context.SaveChanges();
//删 推荐 但必须标明主键
//context.Entry<Student>(new Student() { Id=5,Name = "heyuke", Age = 18 }).State = EntityState.Deleted;
//context.SaveChanges();
//改 推荐
context.Entry<Student>(new Student() { Id=1,Name = "hehe"}).State = EntityState.Modified;
context.SaveChanges();