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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:38:32+00:00 2026-05-15T23:38:32+00:00

Using EF 4.0 Code only i want to make an assocation between an abstract

  • 0

Using EF 4.0 Code only i want to make an assocation between an abstract and normal class.

I have class ‘Item’, ‘ContentBase’ and ‘Test’.

‘ContentBase’ is abstract and ‘Test’ derives from it.

‘ContentBase’ has a property ‘Item’ that links to an instance of ‘Item’.

So that ‘Test.Item’ or any class that derives from ‘ContentBase’ has an ‘Item’ navigation property.

In my DB every record for Test has a matching record for Item.


public class Item
{
    public int Id { get; set;}
}

public abstract class ContentBase
{
    public int ContentId { get; set;}
    public int Id { get; set;}

    public Item Item { get; set;}
}

public class Test : ContentBase
{
    public string Name { get; set;}
}

now some init code

public void SomeInitFunction()
{

    var itemConfig = new EntityConfiguration<Item>();
    itemConfig.HasKey(p => p.Id);
    itemConfig.Property(p => p.Id).IsIdentity();
    this.ContextBuilder.Configurations.Add(itemConfig);

    var testConfig = new EntityConfiguration<Test>();
    testConfig.HasKey(p => p.ContentId);
    testConfig.Property(p => p.ContentId).IsIdentity();

    // the problem 
    testConfig.Relationship(p => p.Item).HasConstraint((p, q) => p.Id == q.Id);

    this.ContextBuilder.Configurations.Add(testConfig);  
}

This gives an error:
A key is registered for the derived type ‘Test’. Keys must be registered for the root type ‘ContentBase’.

anyway i try i get an error. What am i a doing wrong?

  • 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-15T23:38:32+00:00Added an answer on May 15, 2026 at 11:38 pm

    Conclusion so far: Not possible.

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

Sidebar

Related Questions

How to make this css code cross browser compatible using jquery. this code only
I have tried using the code below but it only display results in Chrome
Firstly, I do not want an alternative code, I only want help to make
I try to make a refund transaction via my django app using code: class
I want to make Java code (using Oracle 11g and JDBC also) which will
I want to make java code that does only this: Login to the 'xe'
I created the Layout design using java code only not from the XML Layout
I'm using this code to allow only my ip to access the site <IfModule
I am currently using code similar to this: try { // IE ONLY var
My team is using Entity Framework 4.3.0 - Code Only with POCO classes as

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.