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