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

  • Home
  • SEARCH
  • 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 4247346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:05:43+00:00 2026-05-21T04:05:43+00:00

Per excellent advice I received on a recent question ( Database design problem ),

  • 0

Per excellent advice I received on a recent question (Database design problem),
I am incorporating a super-type/sub-type pattern in a DB I’m
building for an MVC2 app.
I’ll be using Entity Framework to provide the models to MVC.

The super-type is Publications, while the sub-types are Articles,
BlogPosts, etc.
Each sub-type table will have a 2-column composite primary key (pub_id,
pub_type), with foreign keys that reference corresponding columns in the
super-type table

For data integrity purposes (see lengthy comments on accepted solution
to original question) the super-type table should not include the
pub_type in its primary key (unlike the sub-type tables),

And that is where Entity Framework doesn’t seem to play along. Warnings I get when I generate the .edmx file from my existing database:

The relationship ‘FK_Articles_Publications’ has columns that are not
part of the key of the table on the priamry side of the relationship. The relationship was excluded.

(etc.)

QUESTION:
is there any way to coax Entity Framework into mapping the relationship given
the foreign keys I want (or will I have to compromise the DB design and
set a composite key on the supertype table)?

If not, this adds the additional problem of requiring that joing any
other, non-sub-type table (and I plan on several) to the super-type
table requires that I have columns corresponding to both pub_id and
pub_type. For example, I want a topics table to be able to associate
with any kind of publication via the super-type table — I would need
to store (redundantly) the pub_type in a column in the topics table.

I am quite new to EF (and ORM), but it’s power is alluring, and I don’t want to give it up.

  • 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-21T04:05:44+00:00Added an answer on May 21, 2026 at 4:05 am

    In this table,

    CREATE TABLE publications (
      pub_id INTEGER NOT NULL PRIMARY KEY,
      pub_type CHAR(1) CHECK (pub_type IN ('A', 'B', 'P', 'S')),
      pub_url VARCHAR(64) NOT NULL UNIQUE,
      CONSTRAINT publications_superkey UNIQUE (pub_id, pub_type)
    );
    

    it matters that {pub_id} is unique and that {pub_id, pub_type} is unique. (The column pub_type should also be declared NOT NULL.) In the first case, uniqueness guarantees identity. In the second case, uniqueness guarantees that subtypes reference the right kind of row in the supertype. But it doesn’t matter much to the database engine which one is declared PRIMARY KEY and which one is declared UNIQUE. Both can be the target of foreign key references.

    If a dbms were designed around current relational theory, it might support only KEY declarations instead of PRIMARY KEY and NOT NULL UNIQUE.

    So if your ORM can’t cope with constraints the way they’re written, it’s ok to make {pub_id} the primary key in all those tables, and to declare the reducible superkey {pub_id, pub_type} to be unique in all those tables.

    I don’t know whether that will silence EF. You should test tables that reference the subtypes as well as tables that reference the supertype.

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

Sidebar

Related Questions

Per a question I posted yesterday , our website's DNS structure has changed to
Per a conversation with @Aaronaught on another thread, I've started converting my application to
Per the title - are there good built-in options in C#/.NET for fail-safe iteration
Per the Google Page Speed recommendations, I want to Specify image dimensions to Optimize
I'm trying to write a perl script which takes the output of colorgcc (or
Greetings, I am trying to code a solution for an order form pricing calculator
I'm making a restaurant menu using custom post types for the different menu sections.
Important Update: See update 5 at the bottom there is no performance issue in
I'm writing an audio waveform editor in Cocoa with a wide range of zoom
Version 2.3.4 Let's say, I have an items table with some fields, for example:

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.