我正在使用一个遗留数据库愚蠢地设置一个索引,该索引由一个 char id 列和两个分别组成日期和时间的 char 列组成。我为日期和时间列创建了一个 ICompositeUserType
,以映射到实体上的单个 .NET DateTime
属性,该属性在不属于 id 时自行工作。我需要以某种方式使用具有关键属性映射的复合 id,其中包括我的 ICompositeUserType 来映射到两个字符日期和时间列。显然,在我的 Fluent NHibernate 版本中,CompositeIdentityPart
没有 CustomTypeIs()
方法,所以我不能只在我的重写中执行以下操作:
mapping.UseCompositeId()
.WithKeyProperty(x => x.Id, CommonDatabaseFieldNames.Id)
.WithKeyProperty(x => x.FileCreationDateTime)
.CustomTypeIs<FileCreationDateTimeType>();
类似于这甚至可以通过 NHibernate 实现,更不用说 Fluent 了?我没能找到任何关于此的信息。
更新:
更仔细地阅读 NHibernate 文档 后,我发现 NHibernate 确实支持 组件复合 ID ,但它看起来并不支持复合 ID 的自定义类型(即 IUserType
和 ICompositeUserType
)。此外,我拥有的 Fluent 版本不支持 NHibernate 对组件复合 ID 的支持(请参阅 问题 387 和 第 346 期)。我可能会尝试升级我的整个解决方案,看看它是否有效,如果有效的话,然后发布我自己的问题的答案...除非有人可以告诉我,而我不必这样做...8o)
i'm working w/ a legacy database is set-up stupidly with an index composed of a char id column and two char columns which make up a date and time, respectively. I have created a ICompositeUserType
for the date and time columns to map to a single .NET DateTime
property on my entity, which works by itself when not part of the id. i need to somehow use a composite id with key property mapping that includes my ICompositeUserType
for mapping to the two char date and time columns. Apparently w/ my version of Fluent NHibernate, CompositeIdentityPart
doesn't have a CustomTypeIs()
method, so i can't just do the following in my override:
mapping.UseCompositeId()
.WithKeyProperty(x => x.Id, CommonDatabaseFieldNames.Id)
.WithKeyProperty(x => x.FileCreationDateTime)
.CustomTypeIs<FileCreationDateTimeType>();
is something like this even possible w/ NHibernate let alone Fluent? I haven't been able to find anything on this.
UPDATE:
after reading the NHibernate documentation more carefully, i found out that NHibernate does support component composite IDs, but it doesn't look like it supports custom types (i.e. IUserType
and ICompositeUserType
) for composite IDs. Also, the version of Fluent i have doesn't have support for NHibernate's support of component composite IDs (see issue 387 and issue 346). i will probably try and upgrade my entire solution, see if it works, and post an answer to my own question if it does... unless someone can tell me w/o me having to do that... 8o)
发布评论
评论(2)
尝试添加这个
虽然我不确定 CustomSqlType 在一次引用两列时有什么意义。可能没有。您可以创建一个视图,将这些投影到正常日期时间的列吗?
Try adding this
Although I am not sure what sense CustomSqlType does when referring to two columns at once. Probably none. Can you create a view that projects these to columns to normal DateTime?
NHibernate 不支持使用
IUserType
或ICompositeUserTypes
来获取复合 ID。然而,它确实支持组件复合 ID,但 Fluent NHibernate 对此的支持有限。从我在源代码中看到的,它不允许您像 NHibernate 允许的那样指定组件属性的列名称。我现在不得不放弃,只创建两个string
字段,数据库中的两个string
日期字段可以单独映射到,然后有一个DateTime ?
属性转换了两个string
属性。支持 HeavyWave 的评论:“尽管如此,我认为您应该将每一列映射到其自己的字段,并提供组合它们的附加属性。”NHibernate doesn't support the use of
IUserType
orICompositeUserTypes
for composite IDs. It does, however, support component composite IDs, but Fluent NHibernate has limited support for this. From what i could see in the source code, it doesn't allow you to specify the column names for the component properties like NHibernate allows. I had to give-up for now and just create twostring
fields that the twostring
date fields in the database could map to seperately, and then have aDateTime?
property that translated the twostring
properties. Props to HeavyWave for their comment: "Although, I think you should just map each column to its own field and provide additional property that combines them."