0

I have one entity CustomProperty in domain model which is used from several other entities.

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

and

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

But in DB, I do not want just one table CustomProperty which contains nullable foreign key to Product table and another nullable foreign key to Order. Instead, I need two separate tables ProductCustomProperty and OrderCustomProperty.

I need to do that with automapping and conventions. Does anyone have any ideas?

Btw, I have had an idea which does not work for me. Maybe anyone have the clue why:

   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));
         }
   }

This example must have worked perfectly, but IOneToManyCollectionInstance.Table() does not set anything.

Roman Asanov
  • 287
  • 2
  • 6

1 Answers1

0

one-to-many relationships ignore the table, because the FK column goes in the many-side entity.

To put it another way, you can't have a single CustomProperty entity mapped to two different tables (it doesn't make sense).

You can either use a many-to-many mapping, or map CustomProperty as a composite type instead of entity.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154