本文介绍了如何在LINQ中动态写在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下的LinQ查询
I have a LinQ query as below
var filtered=from c in country where c.Id>=5 select c;现在我需要让运算符``> =''是动态的,即运算符可能是``> =''或``==''或``< =''等,具体取决于条件和查询应基于该运算符执行.
Now i need to have the operator ''>='' to be dynamic i.e., the operator may be ''>='' or ''=='' or ''<='' etc depending on a certain criteria and the query should execute based on that operator. How to achieve this in LinQ?
推荐答案您可以添加一个返回bool的检查功能. 像这样的东西: Hi, You could add a check-function which returns a bool. Something like this: private bool TestValue(int id, int contiditon) { if (condition == 1) { return id <= 5; } else { return id >= 5; } } /* your linq query would look like this */ var filtered = from c in country where TestValue(c.Id, c.Condition) select c;
这是完全未经测试的,因此可能包含错误;) 希望这会有所帮助. 致以诚挚的问候,祝您编程愉快, 停止
This is completely untested so it could contain errors ;) Hope this helps. Best regards and happy coding, Stops
如何在水晶报表中使用关闭按钮 How to use the close button in crystal report
更多推荐
如何在LINQ中动态写在哪里?
发布评论