使用此类和映射:
Public class Something
{
public int Id;
public IList<Something> Similarthings { get; set; }
}
public class SomtehingMapping
{
public SomtehingMapping()
{
Map(x => x.Id);
HasManyToMany(x => x.Similarthings )
.Table("SomethingsToSimilarthings")
.ParentKeyColumn("SomethingA_Id")
.ChildKeyColumn("SomethingB_Id")
.Cascade.All();
}
}
你最终得到了这个:
Table SomethingsToSimilarthings
-------------------------------
SomethingA_Id SomethingB_Id
111 222
222 111
是否有任何方法可以定义此映射,以便仅使用一个数据库行来表示双向关系?
答案 0 :(得分:1)
您是否尝试将反向映射属性设置为 true ?
public class SomtehingMapping
{
public SomtehingMapping()
{
Map(x => x.Id);
HasManyToMany(x => x.Similarthings )
.Inverse()
.Table("SomethingsToSimilarthings")
.ParentKeyColumn("SomethingA_Id")
.ChildKeyColumn("SomethingB_Id")
.Cascade.All();
}
}
另一种方法是明确定义关联的另一面并将其标记为inverse="true"