public List <Car> GetAll(Expression <Func <Car, bool> > filter = null) { using (CarsContext context = new CarsContext()) { return(filter == null ? context.Set <Car>().ToList() : context.Set <Car>().Where(filter).ToList()); } }
public Car Get(Expression <Func <Car, bool> > filter) { using (CarsContext context = new CarsContext()) { return(context.Set <Car>().SingleOrDefault(filter)); } }
/// <summary> /// Сохранение /// </summary> public static void Save <T>(T item) where T : class { using (CarsContext db = new CarsContext()) { db.Set <T>().Add(item); db.SaveChanges(); } }
public static void Insert <TEntity>(List <TEntity> entity) where TEntity : class { using (CarsContext context = new CarsContext()) { DbSet <TEntity> dbset = context.Set <TEntity>(); dbset.AddRange(entity); context.SaveChanges(); } }
public static TEntity Find <TEntity>(int id) where TEntity : class { using (CarsContext context = new CarsContext()) { DbSet <TEntity> dbset = context.Set <TEntity>(); TEntity tmp = dbset.Find(id); //context.SaveChanges(); return(tmp); } }
public static void Update <TEntity>(TEntity entity) where TEntity : class { using (CarsContext context = new CarsContext()) { DbSet <TEntity> dbset = context.Set <TEntity>(); context.Entry(entity).State = EntityState.Modified; context.Database.Log = Console.WriteLine; context.SaveChanges(); } }
public RepositoryCRUD(CarsContext _carContext) { context = _carContext; entities = _carContext.Set <TEntity>(); }
public CrudRepository(CarsContext context) { Context = context; DbSet = Context.Set <TEntity>(); }
public virtual async Task <TEntity> Find(int id, CancellationToken cancellationToken) { return(await _context.Set <TEntity>().FindAsync(new object[] { id }, cancellationToken)); }