How Polymorphic Association with TPC Inheritance Mapping is Treated in Professional Projects?

457 Views Asked by At

While designing & developing a data-centered project using Entity Framework, I have spent too much time to find a way to accomplish one of the following but have come across nothing practical.

  1. To find an alternative to implement "Polymorphic Association" which cannot be implemented along with "TPC Inheritance Mapping" in EF - since this kind of inheritance mapping fits well with the logical design of my model, or
  2. To find a way to improve the poor performance of "TPT Inheritance mapping" which seems to me is the only practical alternative to TPC.

"TPH Inheritance Mapping", in my opinion, does not make sense from the "database design" and "data validation" point of view.

Besides, since other parts of the project rely almost totally on Microsoft products, I do not tend to switch to other ORM frameworks such as NHibernate.

Now I would like to ask those of you who are professional software developers and have possibly faced this problem, to please advise me about any other available options/solutions. How is this issue usually solved in professional design/development tasks?

Appreciate any guidance in advance

1

There are 1 best solutions below

0
On

Just playing around I seem to be able to achieve all manner of polymorphic associations. One thing I found helped is to make sure all your foreign keys and relationships are explicitly defined, this will avoid any ambiguity that Code First may encounter. Julie Lerman in her book Code First does mention that foreign keys should be defined otherwise unexpected things with the association mappings may occur.

Hope that helps, if not let us have some code and say what you can't get to work.

Cheers