I have a long sql in which there are multiple where conditions. I want one where condition to only be considered if the value passed is not null
Linq
from b in _context.customer
join d in _context.Address on b.id equals d.Id
join e in _context.units on d.Id equals e.Id
where e.unitNumber == valueProvided)
select new modelAddress
{
address= address
}
value provided can be null so I want the where condition to not take e.unitNumber into account. Also this is just an example, actual query is really large
where e.unitNumber = (valueProvided != null ? valueProvided : e.UnitNumber)
for every nullable condition. This passes these conditions to the SQL to work out, slowing down your query. Down-voting answer attempts simply because you don't agree with them is pretty poor form. – Steve Py