public void Delete(int id) { using (InjectorDatabase dbContext = new InjectorDatabase()) { var entity = dbContext.Set <TDb>().FirstOrDefault(n => n.Id == id); if (entity != null) { dbContext.Set <TDb>().Remove(entity); dbContext.SaveChanges(); } } }
public IEnumerable <T> GetAll() { using (InjectorDatabase dbContext = new InjectorDatabase()) { return(dbContext.Set <TDb>().ToList().Select(entity => entity.MapToEntity <TDb, T>()).ToList()); } }
public void Update(T element) { using (InjectorDatabase dbContext = new InjectorDatabase()) { var entity = dbContext.Set <TDb>().FirstOrDefault(n => n.Id == element.Id); entity?.CopyFieldsFrom(element); dbContext.SaveChanges(); } }
public int Insert(T element) { using (InjectorDatabase dbContext = new InjectorDatabase()) { var entity = dbContext.Set <TDb>().Add(element.MapToEntity <T, TDb>()); dbContext.SaveChanges(); return(entity.Id); } }
public T Get(int id) { using (InjectorDatabase dbContext = new InjectorDatabase()) { var entity = dbContext.Set <TDb>().FirstOrDefault(n => n.Id == id); if (entity != null) { return(entity.MapToEntity <TDb, T>()); } return(default(T)); } }