Esempio n. 1
0
 public static bool Add(SysConfigModel entity)
 {
     using (var context = new PointContexts())
     {
         context.SysConfigs.Add(entity);
         return(context.SaveChanges() >= 1);
     }
 }
Esempio n. 2
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);
     }
 }
Esempio n. 3
0
 protected static T AddEntity(T entity)
 {
     using (var pointContext = new PointContexts())
     {
         pointContext.Entry(entity).State = EntityState.Added;
         //下面的写法统一
         pointContext.SaveChanges();
         return(entity);
     }
 }
Esempio n. 4
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);
     }
 }