LINQ - Using NHibernate, do partial searches on many criteria. LINQ

dynamic-linq linq linq-to-nhibernate

Question

I have a search page where a user can enter multiple cities seperated by a comma and we need to get all the real estate properties where the city is one that is entered in the search criteria. For instance the user will enter something like this

cities = Dallas, Austin

The query I have works fine if the user enters a full city name

var cityList = new List{"Dallas", "Austin"}; var properties = Reporsitory.AsQueryable .Where(x=> cityList.Contains(x.City)) .ToList();

However if I just enter Dal, Aus it does not work. How can I make these partial searches work. Is Dynamic LINQ the only answer? Thanks!

1
1
4/20/2011 1:36:23 PM

Popular Answer

var properties = Reporsitory.AsQueryable().Where(x => cityList.Count(c => x.StartsWith(c)) != 0);

Or replace StartWith to Contains...

0
4/20/2011 1:46:41 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow