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