1

I want to implement Table Per Type inheritance with Entity framework for an existing database.

The database:

alt text

The inheritance for ImageParagraphs works perfect, but I am not able to make a Table Per Type inheritance with LinkListParagraph because of the different primary keys (ParagraphID; ParagraphID+LinkID):

Error 1 Error 3003: Problem in Mapping Fragment starting at line 113: All the key properties (Paragraphs.ParagraphID) of the EntitySet Paragraphs must be mapped to all the key properties (LinkListParagraph.LinkID, LinkListParagraph.ParagraphID) of table LinkListParagraph. C:\Users\buc\Documents\Visual Studio 2008\Projects\ParagraphTest\ParagraphTest\ParagraphModel.edmx 114 15 ParagraphTest

Is there a possiblity to solve this problem without changes to the database?

What I want to do is something like this:

alt text

2 Answers 2

1

One way might be to lie to the Entity Framework about the primary key. This would require going into the store mapping in the EDMX and changing the primary key flags. Realize, however, that if you do this then the Update Model from Database wizard will try to "fix" your mapping every time you do an update.

Another way would be to create a view in your database and map the view instead of the table.

Sign up to request clarification or add additional context in comments.

Comments

0

The main problem comes from the unnecessary default key creations by the entity framework. Try opening .edmx file in xml format and you will now view the following like thing:

<EntityType Name="GSKItemDetails">
          <Key>
            <PropertyRef Name="ItemId" />
            <!--<PropertyRef Name="Description" />
            <PropertyRef Name="NDCNumber" />-->
          </Key>
          <Property Name="ItemId" Type="varchar" Nullable="false" MaxLength="47" />
          <Property Name="Description" Type="varchar" Nullable="false" MaxLength="30" />
          <Property Name="NDCNumber" Type="varchar" Nullable="false" MaxLength="16" />
          <Property Name="UnitPrice" Type="decimal" Precision="19" Scale="4" /> 
        </EntityType>

In my case commentingout the unnecessasary PropertyRefs, as mentioned above, solved the problem of giving error : Error 3003.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.