I think (it is unclear) you mean something like:
IQueryable<YourType> query = /* some basic query; maybe db.TheTable */
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);
// etc
var matches = query.Take(50).ToList();
this uses query composition to issue the most appropriate underlying query it can; for example, if this is LINQ-to-SQL and firstName
and fatherName
are supplied, you would get something like:
select top 50 {some columns} from [dbo].[TheTable] t
where t.FirstName = @p0 and t.FatherName = @p1
<代码>@p0和@p1
均为数值参数。