I have a Person class with the following properties:
public class Person
{
public string LastName { get; set; }
public string FirstName{ get; set; }
public string SecondName { get; set; }
public string Position { get; set; }
}
The user is presented with a search box where they can enter a string separated with spaces. The task is to query from the DB all the Persons that have any property equal to any part of the entered string (the parts are substrings split by spaces). The simplest solution is to OR all possible combinations. But, in my sense, it doesn't seem right. Are there more elegant solutions?
Thanks in advance.
ORmy properties and parts of the entered string now. Something like that:foreach (var s in substrings) foreach (var p in properties) criterion = Restrictions.Or(criterion, Restrictions.InsensitiveLike(p, string.Format("%{0}%", s)));And based on the given answer I'm going to stick with this solution.