1 つの明示的なテーブルにマップできないクラスがあります。マップされるテーブルは、使用されるコンテキストによって異なります。IDictionary<string, int>
基本的に、 をテーブルにバインドしようとしている場合と同じように機能するはずです。
// this is a mapped entity, with a Guid Id, but it can't be mapped to one explicit table
public class NoTableClass : Entity<Guid>
{
}
// the table that this class gets its MyCollectionContext1 from depends on the HasMany mapping for that property
public class MappedClass1 : Entity<Guid>
{
public IEnumerable<NoTableClass> MyCollectionContext1 { get; set; }
}
// the table that this class gets its MyCollectionContext2 from depends on the HasMany mapping for that property
public class MappedClass2 : Entity<Guid>
{
public IEnumerable<NoTableClass> MyCollectionContext2 { get; set; }
}
// Mapping overrides
public void Override(AutoMapping<MappedClass1> mapping)
{
mapping.HasMany(Reveal.Member<MappedClass1, IEnumerable<NoTableClass>>("MyCollectionContext1"))
.Table("Table1")
.Access.Field()
.Cascade.AllDeleteOrphan();
}
public void Override(AutoMapping<MappedClass2> mapping)
{
mapping.HasMany(Reveal.Member<MappedClass2, IEnumerable<NoTableClass>>("MyCollectionContext2"))
.Table("Table2")
.Access.Field()
.Cascade.AllDeleteOrphan();
}
.Table()
コレクションにカスタム クラスがある場合、NHibernate はマッピング メソッドを無視するようです。単純な型の辞書をこのようにマップできる理由がわかりませんが、カスタム クラスを持つコレクションはできません。
注:この問題を解決するために継承/ジェネリックを使用したくない理由と、マッピング先の各テーブルに具体的な型を持たせたくない理由があります。ジェネリックを使用した実用的なソリューションがありますが、それは将来的に他の問題を引き起こします。