“index”和“list-index”有什么区别?

5

在NHibernate中,对于有序集合(如列表)的收集映射,必须映射一个索引列字段。 我刚刚注意到,从NHibernate 2.0开始,似乎还有一个“list-index”属性,它(我相信)可以用于代替索引。

除了能够使用“list-index”指定基础索引值之外,两者之间是否有区别? 使用其中一个是否有任何优势?

2个回答

4

我有同样的问题并阅读了代码。我发现以下内容:

(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);
    }
    // ...
}

对我来说意味着:

  • 基本上是一样的。
  • list-index覆盖了index
  • index的类型设置为int。因此,使用映射文件中的另一种类型时,必须检查实际发生的情况。
  • list-index支持base来告诉它从哪个索引开始。(这在其他地方找到)

0
通过查看XSD,我可以告诉index支持指定type和多个columns,因此它可能可以与自定义类型一起使用(我还没有尝试过)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接