使用NHibernate插入时数据库生成的日期 [英] Database Generated Date on Insert with NHibernate
问题描述
我是NHibernate的新手,所以请多多包涵.
I am a newbie with NHibernate, so please bear with me.
让我们想象一下,我有一个CreatedDate属性,我希望它用sql server datetime值填充.
Let's imagine, i have a property for CreatedDate, and i wanted it to be filled with the sql server datetime value.
我发现的可能解决方案是,用"insert = false"和"update = false"将该属性标记为"generated = always",然后在sql server级别上将CreatedDate设置为默认值(i表示数据库列),为"Getdate()".
The possible solution that i found out is, to mark this property as "generated=always" with "insert=false" and "update=false", and then set the default value for the CreatedDate on sql server level (i mean the database column), to "Getdate()".
这是正确的方法吗?感谢您的宝贵时间,任何建议将不胜感激.
Is this the right approach? Thanks for your time, any suggestion will be well appreciated.
推荐答案
您需要一个nHibernate Audit Interceptor:
You need an nHibernate Audit Interceptor:
http://fgheysels.blogspot.com/2008/07/nhibernate -iinterceptor.html
这篇关于使用NHibernate插入时数据库生成的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!