NHibernate 更新导致选择行的计算列

发布于 2024-10-08 10:32:41 字数 393 浏览 0 评论 0原文

我有一个想要更新的 User 类。我的数据库中有一个用户表,其中有两列:名字和姓氏,还有一个名为 DisplayName 的计算列,它将两列连接起来,中间有一个空格。 DisplayName 的 NHibernate 映射是

<property name="DisplayName" type="string" generated="always"/>

当我更新 User 对象并提交事务时,NHibernate 仅在 DisplayName 属性上运行额外的 select 语句,我假设保持对象和数据库行同步。我不需要它,因为对象随后就超出了范围。

我可以做些什么来告诉 NHibernate 此时不需要获取更新的 DisplayName 吗?

问候, F。

I've got a User class that I want to update. There's a User table in my database with two columns among others: FirstName and Lastname and there's a computed column called DisplayName that concatenates the two with a space in the middle. The NHibernate mapping for DisplayName is

<property name="DisplayName" type="string" generated="always"/>

When I update the User object and commit the transaction, NHibernate runs an extra select statement just on the DisplayName property, I presume to keep the object and the DB row in sync. I don't need that as the object goes out of scope right afterwards.

Is there something I can do to tell NHibernate that there's no need to get the updated DisplayName at this time?

Regards,
F.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

能怎样 2024-10-15 10:32:41

generated="always" 的确切含义是:“这是每次我修改此行时数据库生成的值;请为我刷新它”。

NH 没有“仅在特定列发生更改时才刷新”之类的概念。

我的观点是,您应该在域模型而不是数据库中生成该值。

generated="always" means exactly that: "this is a value generated by the DB every time I modify this row; please refresh it for me".

NH does not have a concept like "only refresh this if a particular column changed".

My opinion is that you should generate that value in your domain model instead of the DB.

貪欢 2024-10-15 10:32:41

generate="always" 替换为 insert="false" update="false"。它将禁用对此列的插入和更新,并且不会执行额外的 select 语句来刷新该值。

Replace generated="always" with insert="false" update="false". It will disable inserts and updates to this column and will not make an extra select statement to refresh the value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文