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 }

 


理解的越多,需要记忆的就越少

posted on 2013-04-08 18:22  零度的火  阅读(240)  评论(0编辑  收藏  举报

导航