WPF made A condition query interface, A, B, C, D, E, F six can query conditions, the user may select one or more, if I write A judge each combination has big dozens, guide for the great god!
CodePudding user response:
Please god give directions!!!!!! I went out for myself!
CodePudding user response:
Method 1: string SQL="select * from XXXXX where 1=1", if a query conditions chose, SQL + SQL="and a=XXXXX" if elected query conditions, b=SQL + SQL and b="XXXXXXX"... By analogy,
Method 2: take ABCDEF... Query conditions of an object, A query condition selected, the object. A assignment, chose B, B is an assignment, and then put the object to your background in the database, want to use the SQL with the above, want to use ef, each judge you if the query object attribute is empty,
Expression
Predicate=a=& gt; True; If (query object. A!="") Predicate=ExpressionHelper. And (predicate, a=& gt; A. field a==query object. A); Else if (query object. B!="") Predicate=ExpressionHelper. And (predicate, a=& gt; A. field B==query object. B); Var result=XXXXXRepository. GetQueryable (predicate) FirstOrDefault (); The thought and method 2 is similar to CodePudding user response:
reference 2 floor however response: method 1: string SQL="select * from XXXXX where 1=1", if elected a query conditions, SQL SQL +="and a=XXXXX" if elected query conditions, b=SQL + SQL and b="XXXXXXX"... By analogy, Method 2: take ABCDEF... Query conditions of an object, A query condition selected, the object. A assignment, chose B, B is an assignment, and then put the object to your background in the database, want to use the SQL with the above, want to use ef, each judge you if the query object attribute is empty, Expression Predicate=a=& gt; True; If (query object. A!="") Predicate=ExpressionHelper. And (predicate, a=& gt; A. field a==query object. A); Else if (query object. B!="") Predicate=ExpressionHelper. And (predicate, a=& gt; A. field B==query object. B); Var result=XXXXXRepository. GetQueryable (predicate) FirstOrDefault (); Thought and method 2 is similar to Great god again to ask what I use is method 1, because the method 2 are not familiar with, so continue to consult method 1. Now I don't know these six conditions customers select several back, if I can write a judge with each combination dozen judgement is a good idea to recommend CodePudding user response:
reference qq_40049431 reply: 3/f Quote: refer to the second floor though reply: Method 1: string SQL="select * from XXXXX where 1=1", if a query conditions chose, SQL + SQL="and a=XXXXX" if elected query conditions, b=SQL + SQL and b="XXXXXXX"... By analogy, Method 2: take ABCDEF... Query conditions of an object, A query condition selected, the object. A assignment, chose B, B is an assignment, and then put the object to your background in the database, want to use the SQL with the above, want to use ef, each judge you if the query object attribute is empty, Expression Predicate=a=& gt; True; If (query object. A!="") Predicate=ExpressionHelper. And (predicate, a=& gt; A. field a==query object. A); Else if (query object. B!="") Predicate=ExpressionHelper. And (predicate, a=& gt; A. field B==query object. B); Var result=XXXXXRepository. GetQueryable (predicate) FirstOrDefault (); Thought and method 2 is similar to Great god again to ask what I use is method 1, because the method 2 are not familiar with, so continue to consult method 1. Now I don't know these six conditions customers select several back, if I can write a judge with each combination dozen judgement is a good idea to recommend ================================================================================ String SQL="select * from XXXXX where 1=1"; If (condition a chose) { SQL SQL +="and a=XXXXX"; } If (condition b) { SQL=SQL + and b="XXXXX"; } If (condition c) { SQL=+ SQL and c="XXXXX"; } If (d chose) { SQL=SQL + and d="XXXXX"; } If e chose (conditions) { SQL=+ SQL and e="XXXXX"; } If (condition f chose) { SQL=+ SQL and f="XXXXX"; } Assume that the user choose the c of e, so the final SQL is String SQL="select * from XXXX where 1=1 and c=XXXXXX and e=XXXXXXX", Assume that the user choose the f, then the final SQL is String SQL="select * from XXXX where 1=1 and f=XXXXXX", Finally put the SQL in database to query CodePudding user response:
references 4 floor however response: ================================================================================ String SQL="select * from XXXXX where 1=1"; If (condition a chose) { SQL SQL +="and a=XXXXX"; } If (condition b) { SQL=SQL + and b="XXXXX"; } If (condition c) { SQL=+ SQL and c="XXXXX"; } If (d chose) { SQL=SQL + and d="XXXXX"; } If e chose (conditions) { SQL=+ SQL and e="XXXXX"; } If (condition f chose) { SQL=+ SQL and f="XXXXX"; } Assume that the user choose the c of e, so the final SQL is String SQL="select * from XXXX where 1=1 and c=XXXXXX and e=XXXXXXX", Assume that the user choose the f, then the final SQL is String SQL="select * from XXXX where 1=1 and f=XXXXXX", Finally put the SQL in database to query Great spirit: that is to say, A, B, C, D, E, F IF you count combination such as AC, BC, EC, ABC, etc that 90 different kinds of group in method 1 IF I was to write 90 IF right method 1 have any other better solution CodePudding user response:
reference 5 floor qq_40049431 reply: Quote: reference 4 floor however response: ================================================================================ String SQL="select * from XXXXX where 1=1"; If (condition a chose) { SQL SQL +="and a=XXXXX"; } If (condition b) { SQL=SQL + and b="XXXXX"; } nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull