当前位置: 首页 > 编程语言 > C#

将Linq中的谓词组合到实体分享

时间:2023-04-10 17:36:17 C#

Linq中的组合谓词到实体这是我的代码片段:protectedExpression_wherePredicate=c=>true;publicvoidmain(){_wherePredicate=_wherePredicate.And(c=>c.createdby==6);_wherePredicate=_wherePredicate.And(c=>c.isdeleted==0);varquery=fromevindataConnection.event_infowhereev.isdeleted==0selectev;结果=query.Where(_wherePredicate).ToList();除非这不起作用,因为linq-to-entities不支持Invoke方法。在linq-to-entities中组合谓词的好方法是什么?事实证明,您需要添加以下内容:result=query。AsExpandable.Where(_wherePredicate)。列表();然后它神奇地起作用了!我跟着这个教程:http://www.albahari.com/nutshell/predicatebuilder.aspx以上是C#学习教程:CombiningPredicatesinLinqtoEntities分享所有内容,如果对大家有用需要了解更多关于C#学习教程,希望大家多多关注—本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: