c# – 在Linq到实体中组合谓词
发布时间:2020-12-15 17:26:34 所属栏目:百科 来源:网络整理
导读:我想动态构建我的条件列表.这是我的代码片段: protected ExpressionFuncevent_info,bool _wherePredicate = c = true;public void main() { _wherePredicate = _wherePredicate.And(c = c.createdby == 6); _wherePredicate = _wherePredicate.And(c = c.is
我想动态构建我的条件列表.这是我的代码片段:
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(); } 除非这不起作用,因为linq-to-entities不支持Invoke方法. 我可以在linq-to-entities中组合谓词的好方法是什么? 解决方法
事实证明,你需要添加这个:
结果= query.AsExpandable.Where(_wherePredicate).ToList(); 然后它就神奇地起作用了! 我按照本教程: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |