public virtual void Update <T>(T entity, bool isSubmit) where T : class { if (isSubmit && _dbEntities == null) { using (DbEntities db = new DbEntities()) { var obj = db.Set <T>(); obj.Attach(entity); db.Entry(entity).State = System.Data.EntityState.Modified; db.SaveChanges(); } } else { _dbEntities.Set <T>().Attach(entity); _dbEntities.Entry(entity).State = System.Data.EntityState.Modified; _dbEntities.SaveChanges(); } }
public virtual T Insert <T>(T entity, bool isSubmit) where T : class { if (isSubmit && _dbEntities == null) { using (DbEntities db = new DbEntities()) { var obj = db.Set <T>(); T result = obj.Add(entity); db.SaveChanges(); return(result); } } else { _dbEntities.Entry(entity); T result = _dbEntities.Set <T>().Add(entity); _dbEntities.SaveChanges(); return(result); } }
public BaseDAL() { dbContext = new DbEntities(); dbContext.Database.Initialize(true); }
public BaseDao() { _dbEntities = new DbEntities(); }