예제 #1
0
        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();
            }
        }
예제 #2
0
 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);
     }
 }
예제 #3
0
 public BaseDAL()
 {
     dbContext = new DbEntities();
     dbContext.Database.Initialize(true);
 }
예제 #4
0
 public BaseDao()
 {
     _dbEntities = new DbEntities();
 }