使用 NHibernate 使用 SQL 服务器端 DEFAULT 值进行插入/更新

发布于 2024-08-28 04:01:34 字数 266 浏览 4 评论 0原文

我们的几个数据库表包含 LastModifiedDate 列。我们希望这些能够基于单一时间源保持同步。在这种情况下,我们最好的时间源是 SQL Server 本身,因为只有一台数据库服务器,但有多个应用程序服务器,这些服务器可能会不同步。

我希望能够使用 NHibernate,但在这些表上更新或插入行时,让它使用 GETUTCDATE() 或 DEFAULT 作为列值。

想法?

编辑:基于缺乏回应,我只能相信这是 NHibernate 无法做到的事情。这让我很难过。

Several of our database tables contain LastModifiedDate columns. We would like these to stay synchronized based on a single time-source. Our best time-source, in this case, is the SQL Server itself since there is only one database server but multiple application servers which could potentially be off sync.

I would like to be able to use NHibernate, but have it use either GETUTCDATE() or DEFAULT for the column value when updating or inserting rows on these tables.

Thoughts?

Edit: Based on the lack of responses, I simply have to believe that this is something that NHibernate is just not capable of doing. This makes me sad.

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

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

发布评论

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

评论(2

白况 2024-09-04 04:01:34

将类属性映射到表列时,设置 insert="false" update="false"。

When mapping the class property to the table column, set insert="false" update="false".

川水往事 2024-09-04 04:01:34

由于您想使用服务器函数进行插入和更新,并且您可能希望在内存中保持一致,因此我建议您使用触发器,然后设置:

insert="false" update="false" generated =“总是”。

这样,每当您保存时,NHibernate 都会从数据库中检索插入/更新的值。

Since you want to use a server function for BOTH insert and update, and you probably want to keep that consistent in memory, I suggest that you use a trigger and then set:

insert="false" update="false" generated="always".

That way, NHibernate will retrieve the inserted/updated value from the DB whenever you save.

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