Exemplo n.º 1
0
 public async Task <T> GetByIdAsync(int id)
 {
     return(await _context.Set <T>().FindAsync(id));
 }
Exemplo n.º 2
0
 public async Task <T> GetByIdAsync(int id) => await Context.Set <T>().FindAsync(id);
Exemplo n.º 3
0
 public async Task <T> GetByIdAsync(int id)
 {
     return(await _context.Set <T>().FindAsync(id));//we use Set because can be used to query and save instances of T. T will replace with whetever type we're passing
 }
Exemplo n.º 4
0
 public void Add(T entity)
 {
     _context.Set <T>().Add(entity);
 }
Exemplo n.º 5
0
 private static bool IsDbSetEmpty <T>(StoreContext context) where T : class => !context.Set <T>().Any();
 /// <summary>
 /// The method calls SpecificationEvaluator's GetQuery static method and send to it all the specifications as a query.
 /// </summary>
 /// <param name="spec">The specifications (conditions) used in a query</param>
 /// <returns>The query</returns>
 private IQueryable <T> ApplySpecification(ISpecification <T> spec)
 {
     return(SpecificationEvaluator <T> .GetQuery(_context.Set <T>().AsQueryable(), spec));
 }
Exemplo n.º 7
0
 public async Task <IReadOnlyList <T> > GetAllAsync()
 {
     return(await _storeContext.Set <T>().ToListAsync());
 }
 /// <inheritdoc />
 public async Task <T> GetByIdAsync(int id)
 {
     return(await _storeContext.Set <T>().SingleOrDefaultAsync(p => p.Id == id));
 }
Exemplo n.º 9
0
 public GenericRepository(StoreContext context)
 {
     _context  = context;
     _entities = _context.Set <T>();
 }
Exemplo n.º 10
0
        //3-methods:

        public async Task <T> GetByIdAsync(int id)
        {
            return(await _Context.Set <T>().FindAsync(id));

            //Set<T>() will be replaced by the Entity we are using in the generic interface, it can be Product, ProductType, .....
        }
        public async Task <T> GetByIdAsync(int id)
        {
            var item = await _context.Set <T>().FindAsync(id);

            return(item);
        }
Exemplo n.º 12
0
 public async Task <T> AddAsync(T entity)
 {
     return((await _context.Set <T>().AddAsync(entity)).Entity);
 }
Exemplo n.º 13
0
 public async Task <IReadOnlyList <T> > GetAllAsync() =>
 await context.Set <T>().ToListAsync();
Exemplo n.º 14
0
 public async Task <T> GetByIdAsync(int id)
 {
     //Set method creates a DbSet that can be used to query and save instances of T
     return(await _context.Set <T>().FindAsync(id));
 }