hn-dotnet/Infrastructure/Repository.cs
2020-12-04 13:47:31 +01:00

24 lines
550 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();
}
}
}