Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Repository.cs 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Linq.Expressions;
  2. using BlackRock.Reporting.API.Core;
  3. using BlackRock.Reporting.API.Core.Models;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace BlackRock.Reporting.API.Persistence
  6. {
  7. // Q: Da li da dozvolimo promene van klase ili da zabranimo pomocu AsNoTracking();
  8. public class Repository<TEntity> : IRepository<TEntity> where TEntity : class
  9. {
  10. private readonly BRDbContext context;
  11. public Repository(BRDbContext context)
  12. {
  13. this.context = context;
  14. }
  15. public async Task<IQueryable<TEntity>> GetAllAsync()
  16. {
  17. var result = await context.Set<TEntity>().ToListAsync();
  18. return result.AsQueryable();
  19. }
  20. public async Task<TEntity> GetByIdAsync(Guid id)
  21. {
  22. return await context.Set<TEntity>()
  23. .FindAsync(id);
  24. }
  25. public async Task AddAsync(TEntity entity)
  26. {
  27. await context.Set<TEntity>().AddAsync(entity);
  28. }
  29. public async Task AddRangeAsync(IEnumerable<TEntity> entities)
  30. {
  31. await context.Set<TEntity>().AddRangeAsync(entities);
  32. }
  33. public void Remove(TEntity entity)
  34. {
  35. context.Set<TEntity>().Remove(entity);
  36. }
  37. public void RemoveRange(IEnumerable<TEntity> entities)
  38. {
  39. context.Set<TEntity>().RemoveRange(entities);
  40. }
  41. }
  42. }