Using O/RM Properly

time to read 2 min | 274 words

Steve has a post comparing DLINQ to other O/RMs, I'm not sure which O/RM solution he is talking about, but it is either not very good and the develpers used the five minutes walk through to do everything. A home grown one may be implemented so naively, but most real ones has ways to handle this properly.

Here is how I would use his examples in NHibernate, notice that at no point I lose any performance.

Summing:

select sum(p.UnitPrice) from Product p

Will result in the correct SQL sent to the server. The calculation will be done on the server, not on the client.

Selecting partial result set in NHibernate:

select p.Name, p.Id from Product p

This will generate the correct SQL to get me just the items that I want.

Selecting a different type in NHibernate (Anonymous types don't exist currently, so you need to implement it yourself):

select new Address(c.Address, c.City, C.Zip) from Customer c

Group by, count(), order by, etc are all supported.