在 Castle Active Record 中创建 2 个相同的外键
我这里有 2 个实体,
比如说
Flight Flight_id - PK 起源-FK1 目的地 - FK2
国家 Country_id - PK 国家 代码
示例代码 舱位 飞行 { 公共 int ID {获取;放; 。
[BelongsTo(Column = "Origin", ForeignKey = "country_id")]
public Countries Origin {get; set;}
[BelongsTo(Column = "destination", ForeignKey = "country_id")]
public Countries Destination {get; set; }
在 Activerecord 上创建架构
时出现错误 有什么替代方案吗?谢谢!
I have here 2 entities
let say
Flight
flight_id - PK
origin - FK1
destination - FK2
Countries
country_id - PK
country
code
sample code
Class Flight
{
public int ID {get; set; }
[BelongsTo(Column = "Origin", ForeignKey = "country_id")]
public Countries Origin {get; set;}
[BelongsTo(Column = "destination", ForeignKey = "country_id")]
public Countries Destination {get; set; }
}
I'm getting an error when creating a schema on Activerecord. What will be an alternative to this? thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将两个键的BelongsTo 属性中的ForeignKey 参数命名为相同的名称。该参数不是您要使用的列的名称,而是实际上 ActiveRecord 在创建架构时用来命名它的约束的名称。
我做了一些假设并通过一个有效的示例扩展了您的代码示例:
You're naming the ForeignKey parameter in the BelongsTo attribute the same for both keys. This parameter is not the name of the column you want to use, but actually the name of the constraint that ActiveRecord uses to name it when creating the schema.
I've made some assumptions and expanded your code sample with an example that works: