using System.Linq.Expressions; using Microsoft.EntityFrameworkCore; namespace HrynCo.NotificationService.DAL.EF.Core; internal abstract class EfRepository where TEntity : class { protected NotificationDbContext DbContext { get; } protected DbSet DbSet { get; } protected EfRepository(NotificationDbContext dbContext) { DbContext = dbContext; DbSet = dbContext.Set(); } protected async Task AddAsync(TEntity entity, CancellationToken ct = default) { await DbSet.AddAsync(entity, ct); } protected async Task AddRangeAsync(IEnumerable entities, CancellationToken ct = default) { await DbSet.AddRangeAsync(entities, ct); } protected void Update(TEntity entity) { DbSet.Update(entity); } protected void Delete(TEntity entity) { DbSet.Remove(entity); } protected void DeleteRange(IEnumerable entities) { DbSet.RemoveRange(entities); } protected Task ExistsAsync(Expression> predicate, CancellationToken ct = default) => DbSet.AnyAsync(predicate, ct); }