2012-09-17 33 views
0

上已經到位數據庫表中我們試圖添加一列的CreationDate流利的NHibernate映射到Oracle 11g和SQLite

mapping.Map(x => x.CreationDate) 
      .Not.Nullable() 
      .Default("to_date('01-01-0001','dd-MM-yyyy')") 

這工作與Oracle完美的罰款,但SQLite的不理解這一點,這是完全正常的,因爲它不知道to_date()函數。

如果我使用

DateTime.MinValue.ToString() 

爲具有或不具有特定的格式的缺省值。然後它將在SQLite中工作,但它不會在Oracle中工作。

有人知道一個解決方案來解決這個問題。

回答

1

離開了默認值,並寫入會議

class CreationDateConvention : IPropertyConvention 
{ 
    public CreationDateConvention(string default) 
    { 
     _default = default; 
    } 

    public void Apply(... instance) 
    { 
     if (instance.Name == "CreationDate") 
      instance.Default(_default) 
    } 
} 


// and while configuring 
...FluentMappings.AddFromAssemblyOf<>().Conventions.Add(new CreationDateConvention(isOracle ? "to_date..." : Datetime.Minvalue.ToString())