【问题标题】:Audit information on a relation table with NHibernate使用 NHibernate 审计关系表上的信息
【发布时间】:2010-11-25 22:17:07
【问题描述】:

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

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

对于school_student.id,我使用自增,pk,不为null,所以不用映射。 NHibernate 自动管理关系,所以我不必映射 school_id 和 student_id。 对于创建,我可以使用 getdate() 函数,所以我不必映射这个字段。

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

【问题讨论】:

    标签: nhibernate sql-server-2008 audit


    【解决方案1】:

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

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

    【讨论】:

    • 但这是一个网络应用程序,每个用户都使用相同的连接字符串。
    猜你喜欢
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 2010-10-12
    相关资源
    最近更新 更多