C# NHibernate:自引用多对多配置问题
我试图理解为什么会出现这样的错误:C# NHibernate:自引用多对多配置问题,c#,nhibernate,fluent-nhibernate,C#,Nhibernate,Fluent Nhibernate,我试图理解为什么会出现这样的错误: The relationship Client.ChildClients to Client.ChildClients has Inverse specified on both sides. Remove Inverse from one side of the relationship. 我有一个包含以下属性的客户端实体: public virtual Iesi.Collections.ISet ChildClients {
The relationship Client.ChildClients to Client.ChildClients has Inverse specified on both sides. Remove Inverse from one side of the relationship.
我有一个包含以下属性的客户端实体:
public virtual Iesi.Collections.ISet ChildClients
{
get
{
return this._ChildClients;
}
set
{
this._ChildClients = value;
}
}
public virtual Iesi.Collections.ISet ParentClients
{
get
{
return this._ParentClients;
}
set
{
this._ParentClients = value;
}
}
HasManyToMany<Client>(x => x.ChildClients)
.Access.Property()
.AsSet()
.Cascade.None()
.LazyLoad()
.Inverse()
.Not.Generic()
.Table("ParentClients_ChildClients")
.FetchType.Join()
.ChildKeyColumns.Add("ClientId1", mapping => mapping.Name("ClientId1")
.Nullable())
.ParentKeyColumns.Add("ClientId", mapping => mapping.Name("ClientId")
.Nullable());
HasManyToMany<Client>(x => x.ParentClients)
.Access.Property()
.AsSet()
.Cascade.None()
.LazyLoad()
.Not.Generic()
.Table("ParentClients_ChildClients")
.FetchType.Join()
.ChildKeyColumns.Add("ClientId", mapping => mapping.Name("ClientId")
.Nullable())
.ParentKeyColumns.Add("ClientId1", mapping => mapping.Name("ClientId1")
.Nullable());
当我试图流畅地配置映射时,我遇到了上面列出的错误。
这是我对这些属性的映射:
public virtual Iesi.Collections.ISet ChildClients
{
get
{
return this._ChildClients;
}
set
{
this._ChildClients = value;
}
}
public virtual Iesi.Collections.ISet ParentClients
{
get
{
return this._ParentClients;
}
set
{
this._ParentClients = value;
}
}
HasManyToMany<Client>(x => x.ChildClients)
.Access.Property()
.AsSet()
.Cascade.None()
.LazyLoad()
.Inverse()
.Not.Generic()
.Table("ParentClients_ChildClients")
.FetchType.Join()
.ChildKeyColumns.Add("ClientId1", mapping => mapping.Name("ClientId1")
.Nullable())
.ParentKeyColumns.Add("ClientId", mapping => mapping.Name("ClientId")
.Nullable());
HasManyToMany<Client>(x => x.ParentClients)
.Access.Property()
.AsSet()
.Cascade.None()
.LazyLoad()
.Not.Generic()
.Table("ParentClients_ChildClients")
.FetchType.Join()
.ChildKeyColumns.Add("ClientId", mapping => mapping.Name("ClientId")
.Nullable())
.ParentKeyColumns.Add("ClientId1", mapping => mapping.Name("ClientId1")
.Nullable());
HasManyToMany(x=>x.ChildClients)
.Access.Property()
1.资产()
.Cascade.None()
.LazyLoad()
.Inverse()
.Not.Generic()
.Table(“父客户\子客户”)
.FetchType.Join()
.ChildKeyColumns.Add(“clientD1”,mapping=>mapping.Name(“clientD1”)
.Nullable())
.ParentKeyColumns.Add(“ClientId”,mapping=>mapping.Name(“ClientId”)
.Nullable());
HasManyToMany(x=>x.ParentClients)
.Access.Property()
1.资产()
.Cascade.None()
.LazyLoad()
.Not.Generic()
.Table(“父客户\子客户”)
.FetchType.Join()
.ChildKeyColumns.Add(“ClientId”,mapping=>mapping.Name(“ClientId”)
.Nullable())
.ParentKeyColumns.Add(“clientD1”,mapping=>mapping.Name(“clientD1”)
.Nullable());
我试图弄清楚我的问题以及为什么会发生。我做错了什么?解决了!问题似乎出在fluent nhibernate验证器或其他方面。但愿我知道为什么会这样做。您必须添加
ForeignKeyConstraintNames
没有它它就无法工作,我不知道为什么。请看这里的工作示例:另外,可能您已经过时了FluentNHibernate(我以前见过这个bug)