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