I think (unclear) you mean something like:
IQueryable<YourType> query = if(!string.IsNullOrEmpty(firstName)) query = query.Where(row => row.FirstName == firstName); if(!string.IsNullOrEmpty(lastName)) query = query.Where(row => row.LastName == lastName); if(!string.IsNullOrEmpty(fatherName)) query = query.Where(row => row.FatherName == fatherName);
this uses the composition of the queries to issue the most appropriate base query; for example, if it is LINQ-to-SQL and firstName and fatherName , you will get something like:
select top 50 {some columns} from [dbo].[TheTable] t where t.FirstName = @p0 and t.FatherName = @p1
where @p0 and @p1 are parameters containing values.
source share