What's the difference between a list, set and bag in the NHibernate mapping file? How does each relate to the .NET collections?
NHibernate semantics:
List: Ordered collection of entities, duplicate allowed. Use a .NET IList
in code. The index column will need to be mapped in NHibernate.
Set: Unordered collection of unique entities, duplicates not allowed. Use Iesi.Collection.ISet
in code (NH prior to v4) or System.Collections.Generic.ISet
(NH v4+). It is important to override GetHashCode
and Equals
to indicate the business definition of duplicate. Can be sorted by defining an orderby or by defining a comparer resulting in a SortedSet
result.
Bag: Unordered list of entities, duplicates allowed. Use a .NET ICollection<T>
in code. The index column of the list is not mapped and not honored by NHibernate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With