使用NHibernate审核关系表的信息

时间:2010-08-29 12:42:26

标签: nhibernate sql-server-2008 audit

我在项目中使用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信息发送到数据库?

1 个答案:

答案 0 :(得分:0)

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

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

相关问题