nhibenrate 中的多行更新

发布于 2024-09-24 19:36:57 字数 201 浏览 2 评论 0原文

所以我想知道是否最好使用 hql 查询来更新数据库中的多行,或者在修改每个对象后调用 nhibernates save 。我知道答案是 HQL 查询,但请给我足够的理由。 但是使用 HQL 查询也有缺点,就像我的 API 对模型有很强的依赖性,如果属性名称发生任何更改,我必须明确记住此查询的存在。

那么利大于弊吗?如果是,请量化。

谢谢。等待您的答复。

So I was wondering whether it is best to update multiple rows in a database using an hql query or calling nhibernates save after modifying each object.. I know that the answer is the HQL query but please give me adequate reasons for the same.
but there are disadvantages of using an HQL query right like my API has a hard dependency on the model if any change in the property name i hv to explicitly remember the existence of this query.

So do the pros outway the cons if yes after please quantify.

Thanks. Awaiting your answers.

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

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

发布评论

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

评论(1

弄潮 2024-10-01 19:36:57

如果您将 HQL 更新语句声明为命名查询,NHibernate 将在构建会话工厂时对其进行验证,并在出现任何错误时抛出异常。因此,如果您更改属性名称并忘记更改 HQL,它将在您的应用程序启动时抛出异常(即快速失败),因此这非常安全。

在我看来,单独加载和保存每个对象对性能来说是一个相当大的影响,我总是尝试让数据库尽可能地完成其工作。

If you declare your HQL update statement as a named query, NHibernate will validate it when it builds the session factory and will throw if there is any error. So if you ever change a property name and forget to change the HQL it will throw when your application starts up (i.e. fail fast), so that makes it quite safe.

Loading and saving each object individually is a pretty big performance hit IMO, I always try to let the database do its job whenever possible.

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