hn-dotnet/Infrastructure/Repository.cs

29 lines
668 B
C#

using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace HN.Infrastructure
{
public abstract class Repository<TEntity> where TEntity : class
{
private readonly HNDbContext _context;
protected readonly DbSet<TEntity> Entries;
protected Repository(HNDbContext context)
{
_context = context;
Entries = _context.Set<TEntity>();
}
protected async Task AddAsync(params TEntity[] entities)
{
await Entries.AddRangeAsync(entities);
await _context.SaveChangesAsync();
}
protected async Task UpdateAsync(params TEntity[] entities)
{
await _context.SaveChangesAsync();
}
}
}