Want to filter Field List in IContentQuery<T> before querying DB

Topics: Writing modules
Aug 29, 2011 at 10:00 AM


I noticed that IContentQuery<T> has Where() and List() methods, amongst others, but there is no Select() method. For me, this is a slight problem because I need to retrieve ONLY one column (out of about 70) and do a distinct on it and then from user input, I will filter that further. THe point is this; I don't want to query the database for the whole lot of data. Returning every field from every row is a little overkill and will be a performance hit. What can I do in this situation? I want to do something like this:

IEnumerable<string> cities = (from x in contentManager.Query<HotelPart>().Where<HotelPartRecord>(h => h.City.Contains(keyword)).List()
                                                     select x.City).Distinct().OrderBy(o => o);

That will work, but it obviously first gets EVERY field from EVERY row in the DB and only THEN filters it for the one column.

Any suggestions?


Aug 29, 2011 at 7:45 PM

It won't get every row: you have a where. You can always go for the repository and make better defined queries, or even go to the nHibernate session and control exactly your query.