0

CustomProperty在域模型中有一个实体,它被其他几个实体使用。

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

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

但在 DB 中,我不希望只有一个表CustomProperty包含可空外键到Product表和另一个可空外键到Order. 相反,我需要两个单独的表ProductCustomPropertyOrderCustomProperty.

我需要通过自动映射和约定来做到这一点。有没有人有任何想法?

顺便说一句,我有一个不适合我的想法。也许有人知道为什么:

   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-many关系忽略该表,因为 FK 列位于多方实体中。

换句话说,您不能将单个 CustomProperty 实体映射到两个不同的表(这没有意义)。

您可以使用many-to-many映射,也可以将 CustomProperty 映射为复合类型而不是实体。

于 2011-03-12T16:34:39.847 回答