我有两个类之间的多对多关系:锦标赛和玩家
我在映射中设置了 Cascade.SaveUpdate,但是在保存 Tournament 实例时,Players 不会保存到 Players 表中。Nhibernate 只在链接表中写入父键列和子键列。数据库是 SQLite。
这些是映射
public TournamentMap()
{
WithTable("Tournaments");
Id(x => x.Name);
Map(x => x.Start).Access.AsLowerCaseField();
Map(x => x.End).Access.AsLowerCaseField();
HasManyToMany<Player>(x => x.Players)
.WithTableName("TournamentsPlayers")
.WithParentKeyColumn("tournamentName")
.WithChildKeyColumn("playerName").AsSet()
.Access.AsLowerCaseField()
.Cascade.SaveUpdate().LazyLoad();
References(x => x.Type).Access.AsLowerCaseField()
.TheColumnNameIs("typeName")
.Cascade.SaveUpdate();
}
public class PlayerMap : ClassMap<Player>
{
public PlayerMap()
{
WithTable("Players");
Id(x => x.Name);
HasManyToMany<Player>(x => x.Tournaments)
.Access.AsLowerCaseField()
.WithTableName("TournamentsPlayers")
.WithParentKeyColumn("playerName")
.WithChildKeyColumn("tournamentName").AsSet()
.Cascade.SaveUpdate().IsInverse().LazyLoad();
}
}