I’ve googled this extensively, but I couldn’t find any good examples:
What collection type can I use best if I need to persist a collection with NHibernate which has a row number? I need to be able to insert, append and delete lines as well as move them up or down the list (may also drag line on position 5 tot line position 3). Is there any list that works together with a row number property? I used a List<> for persistence, but my colleague wrapped another list around it to store the items in order. I wanna get rid of that second list.
Any hints are more than welcome.
Regards, Ted
If the positions start at 0 and there are no gaps you can just use an
IList<>in code and a<list>in the mapping. You don’t need a seperate propery for the position that way, it will be mapped with<index column="pos"/>. You won’t need a second list or any other code for sorting then.Otherwise use an
ICollection<>in code an map it as<set>or<bag>. Then you’ll need a property for the position which you’ll have to manage yourself.