使用 NHibernate 审核关系表上的信息

发布于 2024-09-16 07:07:02 字数 534 浏览 3 评论 0原文

我在一个项目中使用 NHibernate。数据库需要在关系表上具有创建日期和创建者用户字段,但我不想将关系映射到域。我的数据库设计是这样的:

school (id, name, credate, creuser)
student (id, name, credate, creuser)
school_student(id, school_id, student_id, credate, creuser)

对于 school_student.id,我使用 autoincrement,pk,not null,所以我不必映射它。 NHibernate 自动管理关系,因此我不必映射 school_id 和 Student_id。 对于 credate,我可以使用 getdate() 函数,因此我不必映射此字段。

但是对于 creuser 字段,我想不出一种方法,因此我不必为 school_student 表创建域类。如何避免为 school_student 表创建域?每次 NHibernate 向该表插入一条记录时,有没有办法将 creuser 信息发送到数据库?

I am using NHibernate on a project. The database is required to have creation date and creator user fields on relation tables but I do not want to map the relations to domains. My db design is like:

school (id, name, credate, creuser)
student (id, name, credate, creuser)
school_student(id, school_id, student_id, credate, creuser)

For school_student.id, I use autoincrement, pk, not null, so I do not have to map it.
NHibernate automatically manages relations so I do not have to map school_id and student_id.
For credate, I can use getdate() function, so I do not have to map this field.

But for creuser field, I cannot think of a way that so I do not have to create a domain class for school_student table. How can I escape creating a domain for school_student table? Is there a way of sending creuser information to database each time NHibernate inserts a recort into this table?

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

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

发布评论

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

评论(1

淤浪 2024-09-23 07:07:02

您可以使用 SUSER_SNAME() 作为如果是直接连接,则为该列的默认值。

间接地(例如通过网站)您必须发送 Context.User.Identity 因为数据库引擎不知道最终用户是谁。您必须在 nHibernate 中映射它。

You can use SUSER_SNAME() as the default for the column if it's a direct connection.

Indirectly (eg via a web site) you'll have to send the value of Context.User.Identity because the DB engine does not know who the end user is. You'll have to map it in nHibernate.

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