2

NHibernate 4.0.4.4000
.NET 4.5.1

For some reason I can't explain, NHibernate loads my entity's list-property as an string[] instead of a List<string> (or PersistentList or something like that).

I need it to be a List<string> so I can call Clear() on the list.

Question

How can I force NHibernate to load the list as a list and not as an string[]-array?

The entity:

    public class ProductionOrderViewModelResourceLine : AggregateReadModel
    {
        ...
        virtual public IList<string> DifferentialIds { get; set; }
        ...

        protected ProductionOrderViewModelResourceLine()
            : base(null)
        {

            ...

            this.DifferentialIds = new List<string>();
        }

        public ProductionOrderViewModelResourceLine(
            ...
            )
            : base(aggregateId)
        {
            ...
            this.DifferentialIds = new List<string>();
        }
    }

The FluentNHibernate mapping override:

    public class ProductionOrderViewModelResourceLineMapping : IAutoMappingOverride<ProductionOrderViewModelResourceLine>
    {
        public void Override(AutoMapping<ProductionOrderViewModelResourceLine> mapping)
        {
            mapping.HasMany(x => x.DifferentialIds)
                .KeyColumn("ProductionOrderViewModelResourceLineId")
                .Table("ProductionOrderViewModelResourceLineDifferentialIds").Element("DifferentialId")
                .Not.Inverse()
                .Cascade.AllDeleteOrphan()
                .AsList()
                .Not.ReadOnly()
                .Access.BackingField();
        }
    }
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class xmlns="urn:nhibernate-mapping-2.2" name="ProductionExecution.ProductionOrderViewModelResourceLine, EventHandlers, Version=1.0.5709.19658, Culture=neutral, PublicKeyToken=null" table="ProductionOrderViewModelResourceLines">
   ...
    <list access="backfield" cascade="all-delete-orphan" inverse="false" lazy="true" name="DifferentialIds" table="ProductionOrderViewModelResourceLineDifferentialIds" mutable="true">
      <cache usage="read-write" />
      <key foreign-key="FK_OtM_ProductionOrderViewModelResourceLine_DifferentialIds2ProductionOrderViewModelResourceLine">
        <column name="ProductionOrderViewModelResourceLineId" />
      </key>
      <index>
        <column name="`Index`" />
      </index>
      <element type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <column name="DifferentialId" />
      </element>
    </list>
    ...
  </class>
</hibernate-mapping>
David Rettenbacher
  • 5,088
  • 2
  • 36
  • 45

0 Answers0