c# - DbExtensions - Add Where clause with multiple OR clauses -


new dbextensions (just morning), have sql statement looks this

select * mytable (field1 @word)     or (field2 @word)     or (field3 @word)     or (field4 @word)     or (field5 @word) 

i cannot work out how using dbextensions?

this have far

var query = sql     .from("mytable")     .where();  query.appendclause("or", ",", "field1 {0}", new string[] { term }); query.appendclause("or", ",", "field2 {0}", new string[] { term }); query.appendclause("or", ",", "field3 {0}", new string[] { term }); query.appendclause("or", ",", "field4 {0}", new string[] { term }); query.appendclause("or", ",", "field5 {0}", new string[] { term }); 

but not add lots of parameters, there 1 value for. maybe missing something?

var predicate = new stringbuilder(); var parameters = new list<object>();  (int = 0; < words.length; i++) {    if (i > 0) {       predicate.append(" or ");    }    predicate.appendformat("({0} {{{1}}})", getfieldname(i), i);    parameters.add(words[i]); }  var query = sql     .from("mytable")     .where("(" + predicate.tostring() + ")", parameters.toarray()); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -