namespace SanctionsSearch.Worker.Persistence; class EfRepository : IRepository where T : Entity { protected readonly DbContext _context; protected readonly ILogger> _logger; public EfRepository(DbContext context, ILogger> logger) { _context = context; _logger = logger; } public async Task> Find(Expression> predicate) { try { return await _context.Set().Where(predicate).ToListAsync(); } catch (Exception ex) { _logger.LogError(ex, "Error finding entities of type {Type}", typeof(T).Name); return []; } } public async Task Upsert(T entity) { try { var existing = await _context.Set().FindAsync(entity.Id); if (existing is null) { await _context.Set().AddAsync(entity); return; } _context.Entry(existing).CurrentValues.SetValues(entity); } catch (Exception ex) { _logger.LogError(ex, "Error upserting entity of type {Type} with {Id}", typeof(T).Name, entity.Id); } } }