FluentNHibernate - 设置数据库列的默认值(SQL Server) [英] FluentNHibernate - Setting default value for DB columns (SQL Server)
问题描述
有没有人知道我如何通过映射列的默认值来设置,例如当我从映射生成数据库我会有DateTime列有getdate()作为默认值?
我到目前为止已经试过(看起来确实像我所需要的),但它不起作用
<$ p $ ($ x $> $ x code> this.Map(x => x.LastPersistedOn,DateModified)
.Access.Property()
.Default(getdate());
我只是试着设置一些默认值,预期。我使用Fluent作为从Git 24.05.2010检索,所以更新您的副本可能会解决您的问题。
映射
public class SampleEntity
{
public virtual DateTime DateTimeProperty {get;组;
$ b $ pre> public class SampleEntityMap
:ClassMap< SampleEntity>
{
public SampleEntityMap()
{
Map(x => x.DateTimeProperty,DateTimeColumn)
.Access.Property()//实际上不是必要
.Not.Nullable()
.Default(getDate());
$ b这会产生下面的sql(从输出到(
$ pre $ create table SampleEntity(
DateTimeColumn DATETIME default getDate()not null
-
Dom
does anyone know a way how I could set through mapping the default value of a column so for e.g. when I generate DB from mappings I would have DateTime column having getdate() as default value?
I tried so far this (looks exactlly like what I need) but it doesn't work
this.Map(x => x.LastPersistedOn, "DateModified")
.Access.Property()
.Default("getdate()");
I just tried setting some default values and it worked as expected. I am using Fluent as retrieve from Git the 24.05.2010 so updating your copy may solve your problem.
Mapping
public class SampleEntity
{
public virtual DateTime DateTimeProperty { get; set; }
}
With
public class SampleEntityMap
: ClassMap<SampleEntity>
{
public SampleEntityMap()
{
Map(x => x.DateTimeProperty, "DateTimeColumn")
.Access.Property() //actually not necessary
.Not.Nullable()
.Default("getDate()");
}
}
this will produce the following sql (from output to the console)
create table SampleEntity(
DateTimeColumn DATETIME default getDate() not null
)
--
Dom
这篇关于FluentNHibernate - 设置数据库列的默认值(SQL Server)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!