views:

103

answers:

1

I need to get the products in the system that match certain criteria.

How should i decide if I should write an HQL and get all products that match the criteria from DB or write a Linq query directly to the main List that contain all products in the system.

Which should be better performance vise

+3  A: 

An NHibernate query would be better because the filtration of the objects would happen in the database. Using LINQ to Objects you would most likely be returning objects from the database that you don't really want.

Always filter result-sets in the database if you can - this will give you the best performance possible (all other things being equal).

Andrew Hare
"Always filter result-sets in the database if you can" isn't necessarily true for very small result sets.
Pavel Minaev
@Pavel - Do you have any evidence to back up your statement? I would be interested to see a complete example in which it was faster to retrieve all objects from a relational database and filter those objects in memory rather than using a well written query on a properly indexed database.
Andrew Hare