阅读背景:

使用ThenInclude()方法的急切加载的通用存储库?

来源:互联网 

Here is my generic repository:

这是我的通用存储库:

public class Repository<T> : IRepository<T> where T : BaseEntity
{
    private DbContext _dbContext { get; set; }
    private DbSet<T> _dbSet { get; set; }

    public Repository(DbContext context)
    {
        this._dbContext = context;
        this._dbSet = context.Set<T>();
    }

    public IQueryable<T> GetAll(params Expression<Func<T, object>>[] includes)
    {
        IQueryable<T> currentSet = this._dbSet;
        foreach (var item in includes)
        {
            currentSet = currentSet.Include(item);
        }
        return currentSet;
    }

    public T Get(Expression<Func<T, bool>> predicated, 
        params Expression<Func<T, object>>[] includes) 
        => this.GetAll(includes).Where(predicated).FirstOrDefault();
}
p



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: