With this class and mapping:
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("S开发者_StackOverflow中文版omethingsToSimilarthings")
.ParentKeyColumn("SomethingA_Id")
.ChildKeyColumn("SomethingB_Id")
.Cascade.All();
}
}
You end up with this:
Table SomethingsToSimilarthings
-------------------------------
SomethingA_Id SomethingB_Id
111 222
222 111
Is there any way of defining this mapping so that the bidirectional relationship is expressed using just one database row?
Have you tried setting up the inverse mapping attribute to true like that?
public class SomtehingMapping
{
public SomtehingMapping()
{
Map(x => x.Id);
HasManyToMany(x => x.Similarthings )
.Inverse()
.Table("SomethingsToSimilarthings")
.ParentKeyColumn("SomethingA_Id")
.ChildKeyColumn("SomethingB_Id")
.Cascade.All();
}
}
An alternative would be to explicitly define the other side of the association and mark that as inverse="true"
精彩评论