What's the best practice to map to a list of entities that need to be managed by their parent?
Difference is semantic:
However, both bag and list can be represented with IList<> in code - that's perfectly ok, but you have to remember that you cannot rely on order of items in a bag.
When choosing how to map your list, choose the option that best matches your collection - if you don't need order, choose bag, if you need order - choose list.
Sidenote: there's a possibility to control order of items in bag - you have to specify order-by attribute with appropriate sql expression. However do not use this to emulate list behavior - use list directly. Order-by attribute for bags is meant to be used, when order is a result of some other attributes - like ordering of entities by timestamp of last modification.
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