症状和单词,具有多对多关系。我想要Symptom.Words和Word.Symptoms属性。我将这些部分添加到映射中:
单词映射
Set(x => x.Symptoms, s =>
{
s.Table("SymptomWords");
s.Key(k =>
{
k.Column("WordID");
});
}, r =>
{
r.ManyToMany(x =>
{
x.Column("SymptomID");
x.Class(typeof(Symptom));
});
});
症状映射
Set(x => x.Words, s =>
{
s.Table("SymptomWords");
s.Key(k =>
{
k.Column("SymptomID");
});
}, r =>
{
r.ManyToMany(x =>
{
x.Column("WordID");
x.Class(typeof(Word));
});
});
当我按new SchemaExport(cfg).SetOutputFile("p:\\schema.sql").Execute(true, false, false)
导出架构时,交集表的主键出错:
create table SymptomWords (
Id INT not null,
SymptomID integer primary key autoincrement,
WordID INT,
constraint FKD8EFCF9E46390459 foreign key (SymptomID) references Symptom,
constraint FKD8EFCF9EA79E50D0 foreign key (WordID) references Word
);
映射有什么问题?
更新
我发现使用Bag
代替Set
会给出正确的sql:
create table SymptomWords (
Id integer primary key autoincrement,
SymptomID INT,
WordID INT,
constraint FKD8EFCF9E46390459 foreign key (SymptomID) references Symptom,
constraint FKD8EFCF9EA79E50D0 foreign key (WordID) references Word
)
如何处理,相同的单词和症状在关系的另一面不会出现两次,所以Set
更适合这里?