尝试保存对象GridView和GridColumns时出现以下错误
INSERT语句与FOREIGN KEY约束“FK_GridColumn_GridView”冲突。冲突发生在数据库“HighCore”,表“UserProfile.GridView”,列'Id'。
Id列未使用身份规范,而是使用hilo生成
我使用以下映射
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="HighCore.Portal.Domain"
namespace="HighCore.Portal.Domain.Entities" >
<class name="GridView" table="GridView" schema="UserProfile" >
<id name="Id" unsaved-value="0">
<generator class="hilo">
<param name="table">Core.nHibernateUniqueKey</param>
<param name="column">NextHi</param>
<param name="max_lo">10</param>
<param name="where">[Table] = 'GridView' and [Schema]='UserProfile'</param>
</generator>
</id>
<property name="EntityTypeName"/>
<property name="ViewName"/>
<set name="Columns" table="GridColumn" schema="UserProfile" lazy="false" cascade="all-delete-orphan">
<key column="GridViewId" not-null="true" />
<one-to-many class="GridColumn"/>
</set>
</class>
</hibernate-mapping>
和
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="HighCore.Portal.Domain"
namespace="HighCore.Portal.Domain.Entities" >
<class name="GridColumn" table="GridColumn" schema="UserProfile" >
<id name="Id" unsaved-value="0">
<generator class="hilo">
<param name="table">Core.nHibernateUniqueKey</param>
<param name="column">NextHi</param>
<param name="max_lo">10</param>
<param name="where">[Table] = 'GridColumn' and [Schema]='UserProfile'</param>
</generator>
</id>
<component name="Group" class="GroupGridColumn" lazy="false">
<property name="Index" column="GroupIndex"/>
<property name="IsDescendingOrder" column="IsGroupDescendingOrder"/>
</component>
<component name="InnerFilter" class="GridColumnFilter" lazy="false">
<many-to-one name="CompositeFilterInfo" class="CompositeFilterInfo" cascade="all-delete-orphan">
<column name="FilterInfoId"/>
</many-to-one>
<set name="DistinctFilterValues" table="DistinctFilterValue" schema="UserProfile" cascade="all-delete-orphan" inverse="true">
<key column="GridColumnId" not-null="true" />
<one-to-many class="DistinctFilterValue"/>
</set>
</component>
<property name="Member"/>
<property name="Index" column="ColumnIndex"/>
<property name="IsDescendingOrder" />
<property name="Hidden" />
</class>
</hibernate-mapping>
保存gridview的代码
Session.BeginTransaction();
Session.SaveOrUpdate(entity);
Session.Transaction.Commit();