在Linq到实体中组合谓词
我想动态构建我的条件列表。 这是我的代码片段:
protected Expression<Func> _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(); }
除非这不起作用,因为linq-to-entities不支持Invoke方法。
在linq-to-entities中组合谓词的好方法是什么?
事实certificate,你需要添加这个:
结果=查询。 AsExpandable .Where(_wherePredicate)。ToList();
然后它就神奇地起作用了!
我按照本教程: http : //www.albahari.com/nutshell/predicatebuilder.aspx
- 将自定义依赖项属性绑定到自定义WPF样式
- SqlCommand中的字符串列表通过C#中的参数
- Windows手机WebBrowser.Navigating事件表单数据
- 如何知道键盘在文本输入上是否处于活动状态
- C#以下方法或属性之间的调用不明确:’System.Math.Round(double,int)’和’System.Math.Round(decimal,int)
- C#中的委托如何比C / C ++中的函数指针更好?
- 浏览器链接Visual Studio 2013无法正常工作
- InvalidOperationException – TwoWay或OneWayToSource绑定无法在只读属性上运行
- Keys.Shift和Keys.ShiftKey之间的区别