Specifiying Default Value for Datetime property in FluenNhibernate mapping class

一笑奈何 提交于 2019-12-25 02:06:14

问题


imagine we have an object have a property:

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

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

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

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

回答1:


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

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

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


来源:https://stackoverflow.com/questions/22283841/specifiying-default-value-for-datetime-property-in-fluennhibernate-mapping-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!