efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Relational: TPH inheritance mapping pattern

Open rowanmiller opened this issue 12 years ago • 24 comments

rowanmiller avatar May 22 '14 20:05 rowanmiller

The highest priority is to support some form of table per hierarchy a.k.a single table inheritance.

divega avatar Sep 04 '14 16:09 divega

+1 on the various mapping patterns (TPT, TPH, etc) Please don't forget a mix of the two in a single graph.

irperez avatar Feb 06 '15 21:02 irperez

+1 for the inheritance support, at least one strategy.

kidchenko avatar Feb 11 '15 17:02 kidchenko

Please do NOT support mixing strategies...

ErikEJ avatar Feb 11 '15 18:02 ErikEJ

Please do not support inheritance OOB, can this be achieved in a separate package so to make pay for play real?

ilmax avatar Feb 11 '15 18:02 ilmax

Since we do not support inheritance, what better alternative? I was thinking of creating a single class and put all the attributes in it, so work with a single table and a single class, simulating a strategy TPH

kidchenko avatar Feb 11 '15 18:02 kidchenko

Without at least TPH, we cannot use EF. For simple applications, the above scenarios may be fine. But for very complex scenarios especially in a world of medical applications (my company develops medical software for cancer regimens), we would not be able to handle such simple scenarios.

irperez avatar Feb 11 '15 20:02 irperez

@kiide & @irperez - This is just a limitation of the current pre-release versions of EF7. Pre-release are just designed for trying out EF7 so we definitely would not recommend using it to try and write real applications with.

rowanmiller avatar Feb 11 '15 21:02 rowanmiller

Yes i uderstand

kidchenko avatar Feb 15 '15 22:02 kidchenko

As part of EF 7, are you going to fix all the bugs that are currently in 6? Like mapping to the same foreign key for different relationships?

phillip-haydon avatar Apr 16 '15 08:04 phillip-haydon

Moving into 7.0.0 since we are in the process of enabling at least some scenarios at the moment.

rowanmiller avatar May 26 '15 16:05 rowanmiller

For TPH, allow us to pick a custom Discriminator. There should be no reason to store a string field for each row. That is my biggest issue with TPH.

issafram avatar Aug 05 '15 01:08 issafram

@issafram In EF7 you can pick any property for the discriminator.

anpete avatar Aug 05 '15 03:08 anpete

@anpete will it support using enums for the discriminator?

issafram avatar Aug 05 '15 04:08 issafram

@issafram Yes.

anpete avatar Aug 05 '15 16:08 anpete

Any workaround even temporary? Can's live with all subclasses being generated as separated tables.

Is there even a list to exclude base classes?

For instance I have TeacherBase and Teacher, and in fact don't want the TeacherBase at all as a table, I only need Teacher to be generated carrying all properties include the base class'.

weitzhandler avatar Aug 23 '15 02:08 weitzhandler

@weitzhandler, did you try the NotMapped annotation?

Maybe you are asking for TPC (Table Per Concrete Type), but that can get confusing with foreign keys in other tables.

issafram avatar Aug 23 '15 06:08 issafram

I've opened a separate issue. https://github.com/aspnet/EntityFramework/issues/2907

weitzhandler avatar Aug 23 '15 12:08 weitzhandler

@rowanmiller this item seems to represent the inheritance work as a whole and it is assigned to the 7.0.0 release. Should it have a priority and an owner or should we close it?

divega avatar Aug 23 '15 13:08 divega

Yep, changed title to reflect that we are implementing TPH for initial release (we have other issues on the backlog to track enabling other patterns).

Assigning to Andriy since he has the inheritance ball at the moment (for the model building work). We should keep this open until things work well end-to-end.

rowanmiller avatar Aug 24 '15 17:08 rowanmiller