5

For collection mapping in NHibernate with ordered collections such as lists, an index column field must be mapped. I just noticed that, as of NHibernate 2.0, there appears to be a "list-index" property as well, which (I believe) can be used in the place of index.

Asides from being able to specify a base index value with "list-index", is there a difference between the two? Any advantage to using one VS the other?

Remi Despres-Smyth
  • 4,173
  • 3
  • 36
  • 46

2 Answers2

4

I had the same question and read the code. I found the following:

(NH 3.0, Cfg\Collection Binder.cs, #548)

private void BindCollectionIndex(/*...*/)
{
    // ...

    if (listMapping.ListIndex != null)
    {
        iv = new SimpleValue(model.CollectionTable);
        new ValuePropertyBinder(iv, Mappings).BindSimpleValue(
            listMapping.ListIndex,
            IndexedCollection.DefaultIndexColumnName, 
            model.IsOneToMany);
    }
    else if (listMapping.Index != null)
    {
        iv = new SimpleValue(model.CollectionTable);
        listMapping.Index.type = NHibernateUtil.Int32.Name;
        new ValuePropertyBinder(iv, Mappings).BindSimpleValue(
            listMapping.Index, 
            IndexedCollection.DefaultIndexColumnName,
            model.IsOneToMany);
    }
    // ...
}

Which means to me:

  • It is basically the same.
  • list-index overwrites index
  • The type of the index is set to int. So you had to check what actually happens when using another type in the mapping file.
  • list-index supports base to tell it on which index to start. (This is found somewhere else)
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
0

By looking at the XSD, I can tell index supports specifying a type and multiple columns, so it can probably be used with custom types (I haven't tried)

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154