gpt4 book ai didi

c# - 使用 AutoInc 的 FluentMapping ComposedId

转载 作者:太空宇宙 更新时间:2023-11-03 17:06:01 26 4
gpt4 key购买 nike

我正在为公司应用程序创建一个传输数据工具,用于将数据从旧版本移动到新版本,然后再返回。由于现在我们正在使用 NHibernate 和 FluentMapping,我将不得不映射所有旧表,并且有一个具有组合主键的表存在问题。该表如下所示:

public class OldTable {
public string KeyOne {get;set}
public string KeyTwo {get;set}
public string KeyN {get;set}
public int Sequence {get;set}
...
}

而且我需要将上述所有字段映射为复合键,唯一的问题是“序列”基于其他字段递增以避免重复键,其他是外键和简单字符串的混合。有没有办法做这个映射?如果需要创建表达式来计算序列,没问题。

好消息是新系统中的表只使用了一个整数Id。

最佳答案

来自documentation :

You can't use an IIdentifierGenerator to generate composite keys. Instead the application must assign its own identifiers.

您也可以在 HBM XML 模式中看到这一点。 <id>允许 <generator>待指定,但 <composite-id>没有。

这并不是说这个特性不能添加到 NHibernate 中。如果这对您有用,请将您的功能请求提交至 the NHibernate issue tracker .如果此功能已首先在 Hibernate 中实现,则您的功能请求最有可能成功——如果是这样,将其移植过来可能很简单。听起来它可能已经在 Hibernate 中实现了: HHH-2060

关于c# - 使用 AutoInc 的 FluentMapping ComposedId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10801860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com