C# – NHibernate efficiency


Having fallen behind in the world of ORM and modern data access, I'm looking to move away from DataSets (shudder) and into a proper mapping framework.

I've just about got my head around Linq to SQL, an I'm now looking into NHibernate with the view to using it in our next project.

With old school sql and data sets, your sql queries obviously only return the data you want. I also understand that L2S is also clever enough to evaluate its where clauses so that it only ever returns the objects you requested. Is NHibernate the same? And is it the same with Ayende's Linq to NHibernate?

By this i mean, if i do the equivalent of:

Select * from customers where name = "fred"

will it fetch every customer into memory, and then filter out the non-freds, or is it clever enough to only get what it needs in the first place?

If it is intelligent, what are the caveats? Are there certains types of query which cannot be evaluated in this way? What performance issues do i need to be aware of?



Best Solution

A quick answer is that the ORM will check the property name and will transform it to a SQL query that will do you name = .... So it won't load all the customers into the memory to search for the name.

Related Question