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 6633519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:49:22+00:00 2026-05-25T22:49:22+00:00

My situation I have an entity model with a base class ItemBase which defines

  • 0

My situation

I have an entity model with a base class ItemBase which defines an ID, a name and a few other properties. The “ID” column is the identity, the “Name” colum is an unique field in the base table. This base class is also defined as an abstract class. So yes, it is a table in the database, but in EF4 I cannot create instances of this base class.

And I have five different entities that inherit from the base class. (Item1, Item2…Item5) So all of them inherit the properties of ItemBase and additional properties are stored in an alternate table. One table per type. Quite nice, actually!

My problem

An object of type Item2 could have the same name as an object of Item5. This would cause a problem since they would both end up with a record in the ItemBase table, and the Name field would be in conflict. That’s just nasty. So if the Item2 class contains brands of television manufacturers and Item5 contains lists of smartphone manufacturers then “Samsung” cannot be added in both entity sets.

I need a solution that will work around this problem, while keeping it simple. (And without adding the Name field to all child tables, because YUCK!) Suggestions?

Way to solve this?

Because “Name” is in the base table and defined as ‘Unique’, I will end up with conflicts when two different entity classes have the same name. I need a solution where “Name” is in the base table, yet it’s unique per child class only, not unique for the base class…
I could alter the child entities to add a prefix to the name when writing to the table, and removing it again when reading from the table. Or I add another field to the base table indicating the child class linked to it, and make “name”+”link” unique, instead of just “Name”. Both solutions aren’t very pretty and it’s unclear to me how to implement one of those. So is there a better solution or else, how do I implement this nicely?

  • 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-25T22:49:23+00:00Added an answer on May 25, 2026 at 10:49 pm

    It cannot be solved by unique column. The unique key would need to be placed over two columns – one specifying the Name and one specifying the type of derived entity but that is not possible with the inheritance type you selected (Table-per-type) because EF will not create and maintain that additional column for you. That would be possible only with Table-per-hierarchy inheritance where all five child entities are stored in the same table as base class and there is discriminator column to differ among them.

    To solve this with your current design you must either use trigger on base table with some query logic to find if name is unique per child or handle this completely in your application.

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

Sidebar

Related Questions

My situation is as follows. I'm using entity framework (4.0) in which I have
Here's my situation.. Suppose you have the following model entities, which represent single tables
when i create my entity data model i have a situation in the DB
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation, where running a query that filters by an indexed column in
I have situation in which I read a record from a database. And if
I have a Silverlight application which uses 2 separate databases. I have a situation
I have the following situation: I have class User with the follwing properies :
I have a situation where I have 4-5 very similar classes which I'd like

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.