NHibernate 对单个属性的更新会更新 sql 中的所有属性
我正在 NHibernate 中对单个属性执行标准更新。 然而,在提交事务时,sql 更新似乎设置了我映射到表上的所有字段,即使它们没有更改。 这肯定不是 Nhibernate 中的正常行为吧? 难道我做错了什么? 谢谢
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var singleMeeting = session.Load<Meeting>(10193);
singleMeeting.Subject = "This is a test 2";
transaction.Commit();
}
}
I am performing a standard update in NHibernate to a single property. However on commit of the transaction the sql update seems to set all fields I have mapped on the table even though they have not changed. Surely this can't be normal behaviour in Nhibernate? Am I doing something wrong? Thanks
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var singleMeeting = session.Load<Meeting>(10193);
singleMeeting.Subject = "This is a test 2";
transaction.Commit();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是正常行为。 您可以尝试将
dynamic-update="true"
添加到类定义中以覆盖此行为。This is the normal behavior. You can try adding
dynamic-update="true"
to your class definition to override this behavior.出色地。 是的,这是 NHibernate 的正常行为。 您可以使用属性的生成属性来更改行为。 详细信息请参阅 Ayende 的博客。
为什么是这个默认值是因为对于动态,你不会缓存你的查询计划。 通常您不介意通过应用程序服务器和数据库之间的高速网络连接发送更多字节。 除非您要保存长字符串,否则此设置非常合适。
Well. yes this is normal behaviour for NHibernate. You can use generated attribute for your properties to change the behaviour. Details on Ayende's blog.
Why is this default is because with dynamics you don't get your query plan cached. And usually you don't mind that you send few more bytes over high speed network connection between your application server and database. Unless you are saving long strings where this setting is perfectly appropriate.