public IEnumerable <T> GetAll() { using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { KlanikContext _context = _provider.GetService <KlanikContext>(); return(_context.Set <T>().ToList()); } }
public T GetById(Guid id) { using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { KlanikContext _context = _provider.GetService <KlanikContext>(); var set = _modifiers.Aggregate((IQueryable <T>)_context.Set <T>(), (current, include) => current.Include(include)); return(set.FirstOrDefault(x => x.Id == id)); } }
public void Delete(T toRemove) { using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { KlanikContext _context = _provider.GetService <KlanikContext>(); var exists = _context.Set <T>().Any(x => x.Id == toRemove.Id); if (exists) { _context.Entry(toRemove).State = EntityState.Deleted; } _context.SaveChanges(); } }
public void Create(T toCreate) { using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { KlanikContext _context = _provider.GetService <KlanikContext>(); var exists = _context.Set <T>().Any(x => x.Id == toCreate.Id); _context.Entry(toCreate).State = exists ? EntityState.Modified : EntityState.Added; _context.SaveChanges(); } }