I'm using linq to entities(EF). I have a constructor which takes 4 string parameters. Depending on what parameter is not null I have to build the linq query. I can do with if else statements but i also has other constructor with 10 parameters in that case there will be many combinations to check.
Example:
Constructor(p1,p2,p3,p4)
{
var prod= from p in ctxt.products.expand("items\details")
where p.x==p1 && p.xx==p2 && p.xxx==p3 && p.xxxx==p4
select p;
}
In the above where clause there should be condition checks only if the parameter is not null. ie., if p2 is null then the where clause should look like
where p.x==p1 && p.xxx==p3 && p.xxxx==p4
if p2 and p3 are null then
where p.x==p1 && p.xxxx==p4
Can anyone tell me how to handle this. if possible can you give sample code for this