0

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

Kamran
  • 782
  • 10
  • 35
  • _which cannot be implemented along with "TPC Inheritance Mapping"_ Why not? You can add a subclass for each association (like UserComments, InvoiceComments, ... if Comment is polymorphically related), or have you got pol. relations to subtyped classes? – Gert Arnold Apr 03 '12 at 07:45
  • Please take a look at [Polymorphic Associations with TPC is Problematic](http://weblogs.asp.net/manavi/archive/2011/01/03/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-3-table-per-concrete-type-tpc-and-choosing-strategy-guidelines.aspx) – Kamran Apr 03 '12 at 16:29
  • I see, yes. Got confused (again) by the abbreviations. I used PA's in a TPH mapping, which worked very well, but only because I could use subclasses to distinguish between the owners of the data (a bit like I said above). – Gert Arnold Apr 03 '12 at 17:51

1 Answers1

0

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

atreeon
  • 21,799
  • 13
  • 85
  • 104