【问题标题】:Fluent NHibernate Self Reference Table With Composite KeyFluent NHibernate 自引用表与复合键
【发布时间】:2012-10-05 18:04:25
【问题描述】:

我只是想知道这是否可能与流畅的 nhibernate 相关。

我的数据库中有一个自引用表。

Table Service
{
int Season (PK) (FK)
int Service_No (PK)
int ParentService_No (FK)
}

该表有一个复合键作为 Season 和 Service_No,以及用于自引用的外键作为 Season 和 ParentService_No

我尝试在我的服务类中创建一个名为 ChildServices 的集合属性,作为多对多关系。

HasManyToMany(x => x.ChildServices )
.Table("SERVICE")
.Access.Property()
.AsBag()
.Cascade.SaveUpdate()
.LazyLoad()
.Generic()
.ParentKeyColumns.Add("SEASON")
.ParentKeyColumns.Add("SERVICE_NO")
.ChildKeyColumns.Add("SEASON")
.ChildKeyColumns.Add("P_SERVICE_NO");

如果我使用上述映射,它会抛出我的异常,说在集合映射中重复列:Service.ChildServices 列:SEASON

我该怎么做?这是流畅的nhibernate的限制吗?

感谢您回答我的问题。

【问题讨论】:

    标签: fluent-nhibernate fluent-nhibernate-mapping


    【解决方案1】:

    这是 NHibernate 的一个限制。您不能将一列用于两种不同的事物,例如在您的情况下主键和外键。 see my question on the same subject

    您可以尝试猜测 NHibernate 生成的别名,并使用 ParentService_No 列作为外键,并在 service_no 上使用别名作为 where 条件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多