.net&实体框架:使用Iqueryable查询数据库
我有一种方法,该方法采用了iqueryable< tentity>
在应用我的所有过滤器的地方,现在我想通过使用此iQueryable来查询数据库,
例如我所定义的iqueryable,例如:
IQueryable<TEntity> query = Enumerable.Empty<TEntity>().AsQueryable();
然后您可以:例如:
query.Where(q => q.Parameter == true)
然后,它应该将空集合传输到应该查询数据库
代码的存储库:
protected EntityDBContext _context;
protected DbSet<TEntity> _set;
public async Task<List<TEntity>> ReadAsync(IQueryable<TEntity> queryable)
{
// something like this but by using the dbset
return queryable.ToList();
}
还是我应该合并所有过滤器然后查询数据库?
谢谢
I have a method which takes an IQueryable<TEntity>
where all my filters have been applied and now I want to query the database by using this IQueryable
The IQueryable i defined like:
IQueryable<TEntity> query = Enumerable.Empty<TEntity>().AsQueryable();
and then you can for example :
query.Where(q => q.Parameter == true)
and then it should transfer the empty collection to the repository where it should query the database
Code:
protected EntityDBContext _context;
protected DbSet<TEntity> _set;
public async Task<List<TEntity>> ReadAsync(IQueryable<TEntity> queryable)
{
// something like this but by using the dbset
return queryable.ToList();
}
Or should I just merge all the filters and then query the database?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 func 委托使用通用过滤器,
可以将此方法称为此类方法。它也将接受多种条件。
这基本上将返回记录列表。如果您不想通过任何条件,那么它将返回整个实体记录列表。
You can use generic filters using Func delegates like this
You can call this method like this. It will accept multiple conditions as well.
This will basically return the list of records. If you don't want to pass any condition then it will return whole list of entity records.