Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3841282
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:37:55+00:00 2026-05-19T15:37:55+00:00

I followed this article on making a table-per-type inheritance model for my entities, but

  • 0

I followed this article on making a table-per-type inheritance model for my entities, but I get the following error when I try to add an instance of a subclass to the database.

Here is how I create the subtype:

var cust = db.Users.CreateObject<Customer>(); // Customer inherits User
db.Users.AddObject(cust);
db.SaveChanges();

I get the following error when I make that last call:

"A value shared across entities or associations is generated in more than one location. Check that mapping does not split an EntityKey to multiple store-generated columns."

With the following inner exception:

"An item with the same key has already been added."

Any ideas on what I could be missing?

UPDATED WITH REPRO STEPS

Created a blank MS SQL Server 2008 R2 database, and added the following two tables:

Users

  • Id : bigint (PK and set it as the identity column)
  • Name : nvarchar(25) NOT NULL (whatever, some random property

Customers

  • Id : bigint (PK, identity column, and FK on Users.Id)
  • Title : nvarchar(25) NOT NULL (also whatever, some random property)

Next I generated the .edmx entity model from the database, and followed the link at the top verbatim. That is to say, I deleted the association between User and Customer, set User as the base class of Customer, deleted the Id property from the Customer entity, and made sure that the Customer.Id column was mapped to the inherited User.Id property. I then ran the following small program:

using (var db = new EF_Test.testEntities())
{
    var cust = db.Users.CreateObject<Customer>();
    db.Users.AddObject(cust);
    db.SaveChanges();
}

I get the same exceptions I described above. Please let me know if this repro works for you, and if it does, what I’m doing wrong. I’m blocked on this issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:37:55+00:00Added an answer on May 19, 2026 at 3:37 pm

    I finally found the source of my troubles. For those still interested, in the Customers table, the Id column should not have been set to the identity column of the table (PK and the FK dependency are fine though).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed this tutorial http://blogs.wrox.com/article/creating-a-simple-ipad-application-table-view/ (creating a uitableview and populating it). I want
Some 4 years back, I followed this MSDN article for DateTime usage best practices
I've followed this otherwise excellent tutorial on getting Xen working with Ubuntu but am
I've followed this example: RCP+JavaWS but the app just briefly comes up and goes
I followed this article http://www.codeproject.com/KB/sharepoint/ASPNET_to_Sharepoint.aspx and it worked converting my ASP.net Site into SharePoint
Since I followed this article to implement a theme engine in Asp.net MVC website.
I have followed this article and implemented my service and I can open the
I followed this example and it works great but I'm wondering if I can
I want to modify the Catalogsearch of magento. So i followed this inchoo article
I followed the instruction of this article and setup an Redmine site on my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.