I have 4 parameters and I need to check in if condition and give the where condition. How to write it in simple way
Example
var param1, param2, param3, param4;
If(param1 !=0 && param2==0 && param3==0 && param4==0)
{
var query = from x in xx
where x.y== param1
select x;
// where param2,param3, parma4 are 0
}
else If(param1 !=0 && param2 !=0 && param3==0 && param4==0)
{
var query = from x in xx
where x.y== param1 && x.z== param2
select x;
// where param3, parma4 are 0
}
else if .......
and so on
You’re probably looking for something like this:
The downside of that approach is you’re passing redundant parameters to the database some of the time. A better approach would be:
This is a bit more typing, but is going to send the smallest possible query to the database.