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

dynamic-linq linq linq-to-nhibernate

Question

We need to obtain all the real estate listings where the city is one that is specified in the search criteria. I have a search page where a user may input several cities separated by commas. The user may input something like this, for example.

cities are Austin and Dallas

If the user inputs the complete name of the city, my query works as intended.

Dallas and Austin are on the new list "cityList"; the property type is "residential." . AsQueryable Where (x=cityList.Contains(x.City)) is used. ToList();

However, it does not function if I merely type in Dal, Australia. How can I get these partial searches to function? Can Dynamic LINQ be the only solution? 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);

Alternately, change 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