Joh*_*rum 5 c# linq-to-entities
我想动态建立我的条件清单。这是我的代码片段:
protected Expression<Func<event_info, bool>> _wherePredicate = c => true;
public void main()
{
_wherePredicate = _wherePredicate.And(c => c.createdby == 6);
_wherePredicate = _wherePredicate.And(c => c.isdeleted == 0);
var query = from ev in dataConnection.event_info
where ev.isdeleted == 0
select ev;
Results = query.Where(_wherePredicate).ToList();
}
Run Code Online (Sandbox Code Playgroud)
除非这行不通,因为linq-to-entities不支持Invoke方法。
我可以在linq-to-entities中组合谓词的好方法是什么?
事实证明,您需要添加以下内容:
结果=查询。AsExpandable .Where(_wherePredicate).ToList();
然后它就神奇地起作用了!
我遵循了本教程: http://www.albahari.com/nutshell/predicatebuilder.aspx
| 归档时间: |
|
| 查看次数: |
4381 次 |
| 最近记录: |