具有 CustomType 映射的 NHibernate Fluent CompositeId

NHibernate Fluent CompositeId with CustomType mapping

我在创建以下映射时遇到问题:

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?谢谢你的帮助。

已找到解决方案,添加 .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>();