NHibernate-更新身份字段 [英] NHibernate - updating Identity fields

查看:128
本文介绍了NHibernate-更新身份字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以像下面那样更新NHibernate中的ID字段吗?

Can we update Id fields in NHibernate like the following?

MyClass myObj = MyClass.Retrieve(1);

myObj.Id = 999;
myObj.Name = "name name";
myObj.Value = 1000;

MyClass.Update(myObj);

推荐答案

您可以关闭会话,执行原始sql更改主键,然后打开一个新会话.这是唯一可以作为nhibername依赖于主键身份的东西.您将永远永远无法使nhibernate做到这一点.

You can close the session, execute raw sql to change the primary key, and then open a new session. that is the only thing that works as nhibername relies on primary key identity. you will never ever be able to make nhibernate do it.

这篇关于NHibernate-更新身份字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆