I have a linq syntax is used to search database as follows:
a=& gt; A.t dIsDelete!=true & amp; & A.u Status & gt;=0 & amp; & ((a.u LoginName!=null & amp; & A.u LoginName. The Contains (key)) | | (a.u RealName!=null & amp; & A.u RealName. The Contains (key))) Among them, (uLoginName) and (uRealName) is currently the or, but I hope to parameters according to the user to query,
Variables such as: [bLoginName=true] and [variables bRealName=false], only confirm whether uLoginName contain key, and don't care whether uRealName has contains,
This time I hope linq syntax is as follows:
a=& gt; A.t dIsDelete!=true & amp; & A.u Status & gt;=0 & amp; & ((a.u LoginName!=null & amp; & A.u LoginName. The Contains (key))) But can you tell me how to do? Thank you,
CodePudding user response:
A=& gt; A.t dIsDelete!=true & amp; & A.u Status & gt;=0 & amp; & (((a.u LoginName!=null & amp; & A.u LoginName. The Contains (key)) & amp; & ! (a.u RealName!=null & amp; & A.u RealName. The Contains (key)))? (a.u LoginName!=null & amp; & A.u LoginName. The Contains (key)) : (a.u RealName!=null & amp; & A.u RealName. The Contains (key)))
CodePudding user response:
reference 1/f, ancient farming response: a=& gt; A.t dIsDelete!=true & amp; & A.u Status & gt;=0 & amp; & (((a.u LoginName!=null & amp; & A.u LoginName. The Contains (key)) & amp; & ! (a.u RealName!=null & amp; & A.u RealName. The Contains (key)))? (a.u LoginName!=null & amp; & A.u LoginName. The Contains (key)) : (a.u RealName!=null & amp; & A.u RealName. The Contains (key))) Thank you for your reply, I'm sorry I didn't describe clearly problems, specific as follows: I have an HTTP Get Method, in which the keyword parameter is used to do keyword query data table column, While bLoginName and bRealName even bCreateTime... Is employed to identify the parameters such as do you want to do a query on these fields, The past with ADO.NET you can since the SQL statements together, But now use linQ don't know what to do, Trouble guidance again, thank you, CodePudding user response:
Using dynamic splicing linq LinqKit Var where=LinqKit. PredicateBuilder. New<> (a=& gt; A.x x==""); If (xx) { Where=where. And (a=& gt; A.x x==""); } CodePudding user response:
Linq. Dynamic https://blog.csdn.net/xuchen_wang/article/details/90749743