What is the recommended way to generate a zero-based index for an
IList mapping?

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Domain" namespace="Domain" >
        <class name="ProductLine" table="ProductLine">

                <id name="Id" column="Id" type="int">
                        <generator class="native">
                        </generator>
                </id>
                <property name="SortIdx" column="SortIdx" not-null="true"></
property>
                <list name="TrafficLineList" table="TrafficLine" 
cascade="all-delete-
orphan" lazy="true" inverse="true">
                        <key column="ProductLineId" />
                        <list-index column="SortIdx"></list-index>
                        <one-to-many class="TrafficLine" />
                </list>
        </class>
</hibernate-mapping>

Here is the method that adds the child:

        private IList<TrafficLine> _trafficLineList;

        public virtual void AddTrafficLineItem(TrafficLine line)
        {
            line.SortIdx = _trafficLineList.Count;
            _trafficLineList.Add(line);
        }

As you can see above I am simply using the non-zero-based Count
property on the list. Since the index is zero-based and Count is not,
I assign the Count before adding it to the list. Any advice on the
recommended approach please.

BTW, what is the difference between <list-index> and <index>?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to