Category
   protected long _id;
   protected IList _sortRalSiteSortMaps;配置文件
<class name="Category" table="Category">
    <id name="Id" type="Int64" unsaved-value="null">
      <column name="CategoryId" length="8" sql-type="bigint" not-null="true" unique="true" index="PK_Category"/>
      <generator class="native" />
    </id>
   <bag name="SortRalSiteSortMaps" inverse="true" lazy="true" cascade="all-delete-orphan">
      <key column="SortID"/>
      <one-to-many class="RalSiteSortMap"/>
    </bag>
</class>RalSiteSortMap    (关系表,)
        protected long _id;
        protected Category _sort;
配置文件
  <id name="Id" type="Int64" unsaved-value="null">
      <column name="id" length="8" sql-type="bigint" not-null="true" unique="true" index="PK_RalSiteSortMap"/>
      <generator class="native" />
  </id>
    <many-to-one name="Sort" class="Category">
      <column name="SortID" length="8" sql-type="bigint" not-null="true"/>
    </many-to-one>外键也建立好.
分类表Category,关系表RalSiteSortMap .  关系表中存放的是分类的ID
问题描述:当我向分类表插入数据时.   当关系表为空时,正常执行插入语句.当关系表不为空时,会报identifier of an instance of NHModel.Entities.RalSiteSortMap was altered from 16 to 1的错误.
百思不得其解,望指教
  

解决方案 »

  1.   

            public static bool Add(Category item)
            {
                ISession session = NHelper.GetCurrentSession();
                ITransaction it = session.BeginTransaction();
                bool flag = true;
                try
                {
                    session.Save(item);
                    session.Flush();
                    it.Commit();
                }
                catch (Exception ex)
                {
                    flag = false;
                    it.Rollback();
                    throw (ex);
                }
                return flag;
            }
    执行函数
      

  2.   

    哭@#%$^&*$%#^$%^#$%^#$%^#$%^#$%^&*((
      

  3.   

    最后问题解决了,你们知道是为什么吗。因为进行数据操作的时候,session没有关闭,我cao @#$%#%^&$%^*$%^&#$%^  调了二天。cao Q@#$%#$%^&*56