LINQ build in time Silverlight c# -


i have method this:

the parameteres can null

public string getall(string d1, string d2, string d3){      linq } 

i want linq query if d1 no null, if d2 not null, if d1 , d2 no null , posible convinations whit parameters.

i dont want do:

if(d1 != null) //linq opt1 if(d2 != null //linq opt2 if(d1 != null && d2 != null) //linq opt3 

please :(

generally queries in these types of questions have -some- commonality (otherwise, why use 1 method?). perhaps looking conditional filtering.

public string getall(string d1, string d2, string d3) {    using(customdatacontext dc = new customdatacontext())    {      iqueryable<customer> query = dc.customers;      if (d1 != null)      {        query = query.where(c => c.name.startswith(d1));      }      if (d2 != null)      {        query = query.where(c => c.orders.any(o => o.ordernumber == d2));      }      if (d3 != null)      {        query = query.where(c => c.favoritecolor == d3);      }      query =         c in query         order c c.name         select c;       list<customer> results = query.take(5).tolist();      string answer = somemethod(results);      return answer;    } }  

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -