有一个ResourcePackage
类和一个PackageItem
类:
public ResourcePackageMap()
{
DiscriminatorValue((int)ResourceObjectType.Package);
HasMany(x => x.Children).KeyColumn("AggregationObjectId").Cascade.AllDeleteOrphan();
}
public PackageItemMap()
{
Id(x => x.Id, "AggregationLinkId");
References(x => x.ResourceItem, "ChildObjectId");
References(x => x.Package, "AggregationObjectId");
Map(x => x.Order, "OrderWithinAggregation");
Map(x => x.Usage, "Usage");
Table("tbl_Object_Aggregation_Link");
}
我收到一条错误消息:
无法删除集合:[Domain.ResourcePackage.Children#102c589b-fc1c-451d-8300-a0ef00baa21f][SQL: 更新 tbl_Object_Aggregation_Link SET AggregationObjectId = null WHERE AggregationObjectId = @p0] NHibernate.Exceptions.GenericADOException:无法删除集合: [域.ResourcePackage.Children#102c589b-fc1c-451d-8300-a0ef00baa21f] [SQL:更新 tbl_Object_Aggregation_Link SET AggregationObjectId = null WHERE AggregationObjectId = @p0] ---> System.Data.SqlClient.SqlException: 无法将值 NULL 插入“AggregationObjectId”列, 表'KDatabase.dbo.tbl_Object_Aggregation_Link'; 列不允许空值。 更新失败。该语句已终止。
关系表运行如下:
有一个 tbl_Object 表和一个 tbl_Object_Aggregation_Link 表,其中包含 tbl_Object 表的两个外键。
而 tbl_Object_Aggregation_Link 表的映射类为:
public class PackageItemMap : ClassMap<PackageItem>
{
public PackageItemMap()
{
Id(x => x.Id, "AggregationLinkId");
References(x => x.ResourceItem, "ChildObjectId");
References(x => x.Package, "AggregationObjectId");
Map(x => x.Order, "OrderWithinAggregation");
Map(x => x.Usage, "Usage");
Table("tbl_Object_Aggregation_Link");
}
}