2017-05-30 154 views
0

我有麻煩創建以下映射:NHibernate的流利CompositeId與CustomType映射

CompositeId(x => x.Id) 
    .KeyProperty(x => x.SiteId, "SiteID") 
    .KeyProperty(x => x.SomeId, "SomeId") 
    .KeyProperty(x => x.AnotherId, "AnotherId") 
    .KeyProperty(x => x.Dtg, "DTG"); 

此前DTG不是CompositeId的一部分,這樣我就可以把DTG如下:

Map(x => x.Dtg, "DTG").CustomType("DateTime2"); 

它需要DATETIME2爲毫秒是必需的。

現在由於更改,我將不得不將Dtg作爲CompositeId的一部分。

那麼如何將CustomType轉換爲Dtg?謝謝你的幫助。

+0

也許是時候使用代理鍵,而不是用那些複合回事。 –

+0

我建議使用代理鍵替換所有組合鍵,但建議不要使用:( – Xstaci

回答

1

發現的解決方案,增加.CustomType<TimestampType>()不會截斷毫秒:

CompositeId(x => x.Id) 
.KeyProperty(x => x.SiteId, "SiteID") 
.KeyProperty(x => x.SomeId, "SomeId") 
.KeyProperty(x => x.AnotherId, "AnotherId") 
.KeyProperty(x => x.Dtg, "DTG").CustomType<TimestampType>();