Association and inheritance in EF

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Posts: 4
Joined: Fri 03 Jun 2011 10:29

Association and inheritance in EF

Post by bruno92300 » Mon 17 Oct 2011 12:53


I’m just trying to create a big app with EF 4.2using inheritance to inject generic functionalities.

I have three classes : BaseClassA (abstract), DerivedFromA inherited from BaseClassA (table per concrete type) and ClassB.

I tried to create an association between ClassB and DerviedFromA : I can created the constraint at the store level, but at the model level, I just created an association between ClassB and BaseClassA, which is its the base class. If I try to select DerviedFromA as part of the association, ED says that there is a problem with mapping of entity key in the store.

My first idea (not shown here) is to put the entity key in an abstract top level class, having all classes inheriting from it, with some level of abstract classes : all works correctly for classes and generated tables in the store (sync is active), but I have the problem with associations, which seems to need to reference the class where the entity key is really defined (and in this case, it is the top level class!).

First question : is my config of entities wrong?
Second : is it a bad idea to use inheritance and abstract classes to simulate an objet hierarchy?
Third : is it only the ED design which is not programmed to autorize this type of configuation (which could be done directly in the xml files)?

Thanks in advance for your point of view.


Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Mon 24 Oct 2011 12:36

1. There is no need to edit constraints from SSDL manually. It is enough to set the [right click on the model surface > Edit Model Settings > Synchronization > Mapping > "Enable automatic synchronization of storage part and mapping of the model with its conceptual part"] checkbox. After this, just create an association on a diagram (CSDL), and SSDL will be changed correspondingly.

2. We cannot reproduce the problem with the latest (4.1.64) version of Entity Developer basing on your description of the problem. Please try this version and, if the issue persists, send us your model and tell us the steps we should follow using it.

Post Reply