c# - Get result from multiple where conditional statements in LINQ -


i trying result based upon values of variables temp_destinationgroupname, temp_countryname , temp_ratetypeid.

if of these variables null or 0, should not included in clause , rest statements should work , bring result. getting 0 rows using query. kindly suggest me these conditions in clause. tried following solutions on stackoverflow still not getting desired result.

var rows = _customerrateslist.where(w => (w.id != rates.id)  && (w.destinationgroupname == temp_destinationgroupname || temp_destinationgroupname!= null)  && (w.countryname == temp_countryname || temp_countryname!=null)  && (w.ratetypeid == temp_ratetypeid || temp_ratetypeid !=0)); 

you can split in many where make request more readable :

var rows = _customerrateslist.where(w => w.id != rates.id)                              .where(w => w.destinationgroupname != temp_destinationgroupname || temp_destinationgroupname != null)                              .where(w => w.countryname != temp_countryname || temp_countryname != null)                              .where(w => w.ratetypeid != temp_ratetypeid || temp_ratetypeid !=0); 

notice must use != in first conditioon of where, you'll data except when it's null. in logic, may conditions == :

var rows = _customerrateslist.where(w => w.id != rates.id)                              .where(w => w.destinationgroupname == temp_destinationgroupname || temp_destinationgroupname == null)                              .where(w => w.countryname == temp_countryname || temp_countryname == null)                              .where(w => w.ratetypeid == temp_ratetypeid || temp_ratetypeid ==0); 

each where result ienumerable, rows ienumerable. if want list, add .tolist()


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -