我在网上搜索了很多,但没有找到适合我的问题的正确解决方案。
基本上我正在尝试与属性创建多对多关系,但正如标题所说,它应该与接口而不是普通类一起使用。
这些是我在关系中的两个接口:
public interface IFaq
{
IList<IFaqTagReference> FaqTagReferences { get; set; }
...
}
public interface ITag
{
IList<IFaqTagReference> FaqTagReference { get; set; }
...
}
以及指定关系的第三个接口
public interface IFaqTagReference
{
IFaq Faq { get; set; }
ITag Tag { get; set; }
}
在 nhibernate 映射中,我尝试这种方式(通常每个元素都有属性,但它只是不起作用的关系):
var mapper = new ConventionModelMapper();
mapper.Class<Faq>(map =>
{
map.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
map.Set(x => x.FaqTagReferences,
db =>
{
db.Key(km =>
{
km.Column("FaqId");
km.NotNullable(true);
});
db.Table("FaqTagReferences");
db.Cascade(Cascade.None);
db.Inverse(true);
},
r => r.OneToMany(m => m.Class(typeof(FaqTagReference)))
);
});
mapper.Class<Tag>(map =>
{
map.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
map.Set(x => x.FaqTagReferences,
db =>
{
db.Key(km =>
{
km.Column("TagId");
km.NotNullable(true);
});
db.Table("FaqTagReferences");
db.Cascade(Cascade.None);
db.Inverse(true);
},
r => r.OneToMany(m => { m.Class(typeof(FaqTagReference)); })
);
});
mapper.Class<FaqTagReference>(map =>
{
map.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
map.ManyToOne(x => x.Faq, db => { db.Column("FaqId"); db.Class(typeof(Faq)); });
map.ManyToOne(x => x.Tag, db => { db.Column("TagId"); db.Class(typeof(Tag)); });
});
但这会引发以下异常
Could not determine type for:
System.Collections.Generic.IList[[Entities.IFaqTagReference,
BaseInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]],
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, for
columns: NHibernate.Mapping.Column(FaqTagReferences)
感谢您的每一个提示或解决方案