Entity Framework里不用查询直接更新的办法
直接贴示例代码吧
1 public static void UpdateOwnerAndCondo(int buildingID, Action<Building> updateAction) 2 { 3 Building building = new Building(); 4 building.ID = buildingID; 5 using (CafContext context = CafContext.Create()) 6 { 7 context.Configuration.ValidateOnSaveEnabled = false; 8 context.Entry<Building>(building).State = EntityState.Unchanged; 9 updateAction(building); 10 context.SaveChanges(); 11 } 12 building.ID = buildingID; 13 }
理解的越多,需要记忆的就越少