指定FluenNhibernate映射类中Datetime属性的默认值 [英] Specifiying Default Value for Datetime property in FluenNhibernate mapping class

查看:156
本文介绍了指定FluenNhibernate映射类中Datetime属性的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我们有一个对象有一个属性:

imagine we have an object have a property:

//the date which app has been added to the system
    public virtual DateTime SubmitionDate { get; set; }

如何设置 SubmutionDate 的默认值(当前日期) code>在sqlServer 2008中使用映射类?

how can I set default value (current date) for SubmutionDate in the sqlServer 2008 using mapping class?

我这样做,但它不起作用并引发sqlDateTimeException!

I did like this but it doesn't work and raise an sqlDateTimeException!

 Map(x => x.SubmitionDate).Default(System.DateTime.Now.ToString()).Not.Nullable();


推荐答案

仅当您的会话工厂被创建。因此,您不能直接在映射中指定日期。

The mapping is being processed only when your session factory is being created. Therefore you can't specify the date directly in mapping.

然而,您可以指定SQL(或更改为HQL)函数,如下所示:

You can however specify the SQL (or rather HQL) function instead like this:

Map(x => x.SubmitionDate).Default("getdate()").Not.Nullable();

这篇关于指定FluenNhibernate映射类中Datetime属性的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆