FluentNHibernate - setting default value for database columns (SQL Server)

Does anyone know a way that I could set the default collation for a column, for example, for example. when I create a DB from mappings, would I have a DateTime column having getdate () as the default value?

I have tried so far (it looks exactly the way I need it), but it does not work.

this.Map(x => x.LastPersistedOn, "DateModified") .Access.Property() .Default("getdate()"); 
+6
sql-server fluent-nhibernate
source share
2 answers

I just tried to set some defaults and it worked as expected. I use Fluent to get from Git 05/24/2010, so updating your copy may solve your problem.
Display

 public class SampleEntity { public virtual DateTime DateTimeProperty { get; set; } } 

FROM

  public class SampleEntityMap : ClassMap<SampleEntity> { public SampleEntityMap() { Map(x => x.DateTimeProperty, "DateTimeColumn") .Access.Property() //actually not necessary .Not.Nullable() .Default("getDate()"); } } 

this will result in the creation of the next sql (from console output)

 create table SampleEntity( DateTimeColumn DATETIME default getDate() not null ) 

- Page Home

+6
source share

The way to do this is to set the current DateTime in the code, rather than using the default value in the database. Then treat it like a regular column. At first, it seemed a little strange to me based on a model-oriented model background, but managing the default values ​​at the POCO level is the DDD way to do this.

It would be nice to hear the opinions of others.

+4
source share

All Articles