Exemplo n.º 1
0
 public static bool DeleteEntity(T entity)
 {
     using (var pointContext = new PointContexts())
     {
         pointContext.Set <T>().Attach(entity);
         pointContext.Entry <T>(entity).State = EntityState.Deleted;
         return(pointContext.SaveChanges() > 0);
     }
 }
Exemplo n.º 2
0
 protected static bool UpdateEntity(T entity)
 {
     //EF4.0的写法
     //Db.CreateObjectSet<T>().Addach(entity);
     //Db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
     //EF5.0的写法
     using (var pointContext = new PointContexts())
     {
         pointContext.Set <T>().Attach(entity);
         pointContext.Entry <T>(entity).State = EntityState.Modified;
         return(pointContext.SaveChanges() > 0);
     }
 }