I have a scenario where I only want use WHERE
clause when it is necessary, otherwise I just want to run my LINQ query without that WHERE
clause.
For example:
if string name = "";
var res = (from a in db.person
select new() { Name = a.FullName, DOB = a.DOB }).ToList();
if string name = "satya";
var res = (from a in db.person
where a.person.contains(name)
select new() { Name = a.FullName, DOB = a.DOB }).ToList();
I know for this we have to write separate 2 queries separately, but without writing separate queries, how can we combine them into a single query?
You can do:
Alternatively, here using the fluent syntax, you can build your query and execute it once you're done: