How do I map a linked table to an inherited object (table per hierarchy)?

I have these tables in my database.

alt text http://img166.imageshack.us/img166/3133/testdbschemafy5.png

With Entity Framework, I would like to have something like this:

alt text http://img166.imageshack.us/img166/5721/testdbschemaefdv5.png

I used inheritance based on each hierarchy, so I added a new premium user object and mapped it to a custom object with conditions for the IsPremiumUser property. I would like the PremiumAccount table to be associated with the PremiumUser object, but it won't work the way I did it: - / I have this error message:

Error 3021: Problem displaying snippet starting at line 113: Each of the following columns in the PremiumAccount table maps to multiple conceptual side properties: PremiumAccount.UserID maps to

Is there any solution to my problem? Can a PremiumAccount object be associated with an inherited object? Is there any other way to do this?

0


source to share


1 answer


I think the PK field of the subtype should be removed (since it inherits from its supertype).



However, this is not a good candidate for inheritance. Entity inheritance should only be done if the type cannot change for the object. It is more of a "candidate for the role", so the real relationship is 1: 1. The point is that the User can lose / gain the Premium role on a regular basis, but you cannot change the type of an existing entity instance (== table rows), even if it seems that you can just change the data in the database. Inheritance mapping are strict rules, you cannot bend them, since inheritance is essentially the interpretation of data in a database, since relational models do not know the concept of inheritance (although some database "cheats" allow you to inherit in SQL DDL such as postgresql)

+2


source







All Articles