首先,我建议您从 repository.GetRows()返回 IQueryable
然后您可以执行如下查询:-
public List<Entity.Student> SearchStudent(string Name, int Age, string EmailAddress, string CountryName)
{
IQueryable<Entity.Student> lstStudents = this.GetAllStudent();
if (!string.IsNullOrEmpty(Name))
{
lstStudents = lstStudents.Where(node => node.FirstName.Equals(Name) || node.LastName.Equals(Name));
}
if (Age > 0)
{
lstStudents = lstStudents.Where(node => node.Age == Age);
}
if (!string.IsNullOrEmpty(EmailAddress))
{
lstStudents = lstStudents.Where(node => node.Email.Equals(EmailAddress));
}
if (!string.IsNullOrEmpty(CountryName))
{
lstStudents = lstStudents.Where(node => node.Country .Equals(CountryName));
}
return lstStudents.ToList<Entity.Student>();
}
这种方式是DLinq专家推荐的。