NHibernate 4.0.4.4000
.NET 4.5.1
由于某些原因我无法解释,NHibernate将我的实体的list-property加载为string[]
而不是List<string>
(或PersistentList
或类似的东西)。
我需要它为List<string>
,因此我可以在列表中调用Clear()
。
我如何强制NHibernate将列表作为列表而不是string[]
- 数组加载?
实体:
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>();
}
}
FluentNHibernate映射覆盖:
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>