Bidirectional one-to-many associations with indexed collections in NHibernate
Posted
by Jørn Schou-Rode
on Stack Overflow
See other posts from Stack Overflow
or by Jørn Schou-Rode
Published on 2010-04-15T08:29:32Z
Indexed on
2010/04/15
8:33 UTC
Read the original article
Hit count: 367
nhibernate
Last summer, I asked a question regarding how to add new object to an IList mapped as a one-to-many with NHibernate. One of the answers let me to this paragraph in the documentation:
Please note that NHibernate does not support bidirectional one-to-many associations with an indexed collection (list, map or array) as the "many" end, you have to use a set or bag mapping.
While I am pretty sure I understand what this paragraph says, I have no idea why or how to work around this limitation. As I am now again working with a model that seems to require a "bidirectional one-to-many association with an index collection", I figured the time was right for follow-up questions:
Why does NHibernate have this limitation on associations? It is my impression that the guys behind NHibernate are quite clever, so I assume there is a pretty good reason.
What are the common workarounds for this shortcoming? Making the collection a non-indexed bag and adding an explicit
Position
property to the child class? Any better solutions?
© Stack Overflow or respective owner