Пример #1
0
        public static void AddOrCreateEntity <T>(this EStoreEntities db, T entity) where T : class, IdEntity
        {
            var entityState = entity.Id == 0 ? EntityState.Added : EntityState.Modified;

            db.Entry(entity).State = entityState;
            db.SaveChanges();
        }
Пример #2
0
 public static void AttachIfDetached <T>(this EStoreEntities db, T entity)
     where T : class
 {
     if (db.Entry(entity).State == EntityState.Detached)
     {
         db.Set <T>().Attach(entity);
     }
 }
Пример #3
0
 public static void Detach <TEntity>(this EStoreEntities _db, TEntity entity) where TEntity : class
 {
     _db.Entry(entity).State = EntityState.Detached;
 }
Пример #4
0
 public static void Save <T>(this EStoreEntities db, T entity) where T : class, IdEntity
 {
     db.Set <T>().Attach(entity);
     db.Entry(entity).State = entity.Id == 0 ? EntityState.Added : EntityState.Modified;
     db.SaveChanges();
 }
Пример #5
0
 public static void AttachAndAdd <T>(this EStoreEntities db, T entity) where T : class, IdEntity
 {
     db.Set <T>().Attach(entity);
     db.Entry(entity).State = EntityState.Added;
 }