问题描述
我正在尝试编写LINQ语句,其中where子句是字符串变量.例如:
string whereClause = "(Code = '12') AND (Name = 'a')" ;
var referreds = from r in _db.Referreds where whereClause;
我有一个具有30个属性的模型,我想为此模型创建搜索.我想选择用户为每个属性插入值的项目.
例如,用户在其中插入具有此属性的Code& Name&家庭搜索的值,并在其中插入Gender,Name,Study,Degree搜索的值的Gender,.
哪个是更好的解决方案?
Linq默认情况下不具有此功能.您必须使用第三方库来做您想做的事.
请查看Scott GU撰写的有关此主题的博客.
http://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library
I am trying to make a LINQ statement where the where clause is a string variable. For example:
string whereClause = "(Code = '12') AND (Name = 'a')" ;
var referreds = from r in _db.Referreds where whereClause;
Edit: I have a model with 30 property, i want to created search for this model. I want to select items where user insert value for every property.
For example, where user insert value for Code&Name&Family serach with this propertie, and where user insert value for Gender,Name,Study,Degree serach with this.
which is Better solution for this?
Linq doesn't have this functionality by default. You have to use a third party library to do what you want.
Check out this blog by Scott GU on the subject.
http://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library
这篇关于如何在linq where子句中使用字符串变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!