Here’s a subtlety of NHibernate mapping that I ran into this morning.
When you map a one-to-many relationship as a list, you can have
null values in that list when loaded.
Imagine you have a typical ordering system, with Orders and OrderLines.
For demonstration purposes, please also imagine that you’ve mapped the OrderLines as List
So, for Order #1023, the OrderLines table might look like this:
Note that there’s no Line #3 in this table.
When NHibernate loads the Order Lines into memory, the List will have a
Count of 4, with Lines at indexes 1, 2
and 4. At position 3 in the list will be a null.
In other words, NHibernate fully honours the LineNumber property, even if that results in
null values in the list.
Oren Eini has more information.