使用 NHibernate 审核关系表上的信息
我在一个项目中使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
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.