我想给继承类提供一个where子句给我的查询的机会。这可能吗?IQueryable where子句被继承类重写
protected IQueryable<EntityResult> GetEntities(ETBDataContext pContext)
{
return from e in pContext.Entities
where e.StatusCode == "Published"
//is there a way to add a dynamic where clause here?
//I would like to ask the inherited class for it's input:
&& e.OtherColumn == "OtherValue" // <-- like GetWhere(e)?
//without having to select the column
orderby e.PublishDate descending
select new EntityResult
{
Name = e.Name,
Link = e.Link
};
}
先谢谢了!!!!!!!!!!
非常感谢。此代码第一次编译和工作。只有一个问题:所有这些仍然是在数据源上执行还是将其加载到内存中然后进行过滤? –
有趣的是,我从来没有想过在第一种方法中分裂它。 –
只要您使用'IQueryable',就不会在数据库中执行任何操作。只有在调用.ToList()或类似的函数时,或者在结果上开始执行foreach才会实际执行针对数据库的查询。 – jeroenh