nhibernate identifier of an instance of was altered from 16 to 1

wanghao2979 2011-07-23 04:15:00
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的错误.
百思不得其解,望指教
...全文
1315 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wu_hong_min 2011-07-25
  • 打赏
  • 举报
回复
session没有关。。。。。
FOR-YOU 2011-07-25
  • 打赏
  • 举报
回复
呵呵 要细心
confidenceyu 2011-07-25
  • 打赏
  • 举报
回复
接分。。
threenewbee 2011-07-25
  • 打赏
  • 举报
回复
问题解决了?
wanghao2979 2011-07-25
  • 打赏
  • 举报
回复
最后问题解决了,你们知道是为什么吗。因为进行数据操作的时候,session没有关闭,我cao @#$%#%^&$%^*$%^&#$%^ 调了二天。cao Q@#$%#$%^&*56
wanghao2979 2011-07-23
  • 打赏
  • 举报
回复
哭@#%$^&*$%#^$%^#$%^#$%^#$%^#$%^&*((
wanghao2979 2011-07-23
  • 打赏
  • 举报
回复
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;
}
执行函数

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧