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 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();
 }