DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/QueryContainer.cs
2024-08-19 10:01:07 +05:00

28 lines
766 B
C#

using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
namespace AsbCloudInfrastructure.Repository;
public class QueryContainer<TEntity> where TEntity : class, IId
{
protected readonly IAsbCloudDbContext dbContext;
protected readonly DbSet<TEntity> dbSet;
protected readonly Func<IQueryable<TEntity>> GetQuery;
public QueryContainer(IAsbCloudDbContext context)
{
dbContext = context;
dbSet = context.Set<TEntity>();
GetQuery = () => dbSet;
}
public QueryContainer(IAsbCloudDbContext context, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
{
dbContext = context;
dbSet = context.Set<TEntity>();
GetQuery = () => makeQuery(dbSet);
}
}