c# - Linq query from user input -


i'm new linq , ran usage don't understand. in ado .net, sql statements strings. when user's input impacted query, easy enough build string sql based on user's selection of checkboxs or drop down lists.

in current application have 3 different drop down boxes user can select various values query. let's each drop down has 10 values. it's easy separate linq query each possible combination not practical.

if know user has selected value in combobox, can code linq query. if user hasn't selected value?

how handle select criteria may or may not there?

thanks


so based on input i've written this;

private datatable filterdmrmarcids()     {         var tmpvalue = dtdmrmarc.asenumerable();          if (chekbcountry.checked)         {             tmpvalue = tmpvalue.where(contact => contact.field<string>("country") == cbcountry.selecteditem);         }         if (chekbstate.checked){             tmpvalue = tmpvalue.where(contact => contact.field<string>("state") == cbstate.selecteditem);         }         return tmpvalue.copytodatatable<datarow>();     }    // filterdmrmarcids() ... 

where dtdata datatable , cbcountry , cbstate comboboxs containing strings.

the problem returns first matching record , not of other matching records.

any suggestions?

without having more details actual code.

ienumerable , iqueryable can built easily. each operation returns ienumerable or iqueryable, can chain them like.

here's example:

public ienumerable<value> getvalues(ienumerable<value> values, string filter1, string filter2, string filter3) {     if (filter1 != null)         values = values.where(v => v.attribute1 == filter1)     if (filter2 != null)         values = values.where(v => v.attribute2 == filter2)     if (filter3 != null)         values = values.where(v => v.attribute3 == filter3)     return values; } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -