0

CustomProperty他のいくつかのエンティティから使用されるドメイン モデルに1 つのエンティティがあります。

Product
{
    int Id;
    Collection<CustomProperty> CustomProperties;
}

Order
{
    int Id;
    Collection<CustomProperty> CustomProperties;
}

しかし、DB では、テーブルへの null 許容外部キーと への別の null 許容外部CustomPropertyキーを含む1 つのテーブルだけは必要ありません。代わりに、2 つの別個のテーブルとが必要です。ProductOrderProductCustomPropertyOrderCustomProperty

自動マッピングと規則でそれを行う必要があります。誰にもアイデアはありますか?

ところで、私にはうまくいかないアイデアがありました。多分誰もが理由の手がかりを持っています:

   public class CustomPropertyConvention : IHasManyConvention, IHasManyConventionAcceptance
   {
         public void Apply(IOneToManyCollectionInstance instance)
         {
                instance.Table("ProductCustomProperty");
         }

         public void Accept(IAcceptanceCriteria<IOneToManyCollectionInspector> criteria)
         {
                criteria.Expect(i => i.Relationship.Class.Name == "CustomProperty" && i.Relationship.EntityType == typeof(Product));
         }
   }

この例は完全に機能したに違いありませんが、 IOneToManyCollectionInstance.Table() は何も設定していません。

4

1 に答える 1

0

one-to-manyFK 列は多面エンティティに含まれるため、リレーションシップはテーブルを無視します。

別の言い方をすれば、1 つの CustomProperty エンティティを 2 つの異なるテーブルにマップすることはできません (意味がありません)。

many-to-manyマッピングを使用するか、 CustomProperty をエンティティの代わりに複合型としてマップすることができます。

于 2011-03-12T16:34:39.847 に答える