| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System.Linq.Expressions;
- using BlackRock.Reporting.API.Core;
- using BlackRock.Reporting.API.Core.Models;
- using Microsoft.EntityFrameworkCore;
-
- namespace BlackRock.Reporting.API.Persistence
- {
- // Q: Da li da dozvolimo promene van klase ili da zabranimo pomocu AsNoTracking();
- public class Repository<TEntity> : IRepository<TEntity> where TEntity : class
- {
- private readonly BRDbContext context;
- public Repository(BRDbContext context)
- {
- this.context = context;
- }
- public async Task<IQueryable<TEntity>> GetAllAsync()
- {
- var result = await context.Set<TEntity>().ToListAsync();
- return result.AsQueryable();
- }
- public async Task<TEntity> GetByIdAsync(Guid id)
- {
- return await context.Set<TEntity>()
- .FindAsync(id);
- }
- public async Task AddAsync(TEntity entity)
- {
- await context.Set<TEntity>().AddAsync(entity);
- }
- public async Task AddRangeAsync(IEnumerable<TEntity> entities)
- {
- await context.Set<TEntity>().AddRangeAsync(entities);
- }
- public void Remove(TEntity entity)
- {
- context.Set<TEntity>().Remove(entity);
- }
- public void RemoveRange(IEnumerable<TEntity> entities)
- {
- context.Set<TEntity>().RemoveRange(entities);
- }
- }
- }
|