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(); }
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); } }
public static void Detach <TEntity>(this EStoreEntities _db, TEntity entity) where TEntity : class { _db.Entry(entity).State = EntityState.Detached; }
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(); }
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; }