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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:54:43+00:00 2026-05-29T06:54:43+00:00

UPDATE : I updated the classes to look more like my actual model. When

  • 0

UPDATE:
I updated the classes to look more like my actual model. When I remove the Assignable property from the Document base entity, everything works.

Is something like this possible to map in EF 4.1?

public abstract class Entity
{
   public Guid Id {get;set;}
}    

public abstract class Assignable:Entity
    {

    }

    public class Contact: Assignable
    {
         public string Name {get;set;}
    }

    public class Partner: Assignable
    {
         public string Area {get;set;}
    }

    public abstract class Document: Entity        {

         public Guid AssignedToId {get;set}
         public Assignable AssignedTo {get;set;
    }

    public class Submittal: Document
    {
         public string SomeProperty {get;set;}
    }

Mapping:

    public class EntityConfiguration<TEntity> : EntityTypeConfiguration<TEntity>
        where TEntity : Entity
        {
            protected EntityConfiguration()
            {
                HasKey(e => e.Id);
                Property(e => e.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            }
        }

    public class AssignableEntityMapping<TEntity>: EntityConfiguration<TEntity> where TEntity: Assignable
{

}
    public class DocumentEntityMapping<TEntity>: EntityConfiguration<TEntity>
        {
            public DocumentEntityMapping()
            {

                HasOptional(e => e.AssignedTo).WithMany().HasForeignKey(e => e.AssignedToId);
            } 
        }

public class ContactMapping: AssignableEntityMapping<Contact>
{
....
}

public class PartnerMapping: AssignableEntityMapping<Partner>
{
....
}

public class SubmittalMapping: DocumentEntityMapping<Submittal>
{
....
}

If this is possible how do I setup the mapping so that the AssignedToId is a foreign key to one of the concrete entities? I created a mapping for the Document entity and I get the error: “The property ‘Id’ is not a declared property on type…” I am guessing it is because EF doesn’t know how to discriminate what the AssignedToId refers to?

  • 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-29T06:54:44+00:00Added an answer on May 29, 2026 at 6:54 am

    I had a lot of extra architecture around the Contact and Partner entities that I could not use something like a TPH (Table Per Hierarchy) approach. EF doesn’t know how to map the AssignedToId in the Document class since i was trying to use Table per Concrete Type (TPC) at the same time. I ended up just adding all the “assignable” types to the Document class for now. If there is another way around this, I’d like to know.

    public abstract class Document: Entity
    {
         public Guid? AssignedContactId {get;set;}
         public Contact AssignedContact {get;set;}
         public Guid? AssignedPartnerId {get;set;}
         public Partner AssignedPartner {get;set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have page-specific javascript files that look something like: $(document).ready(function () { namespace.home.list
Updated question given Andrew Hare's correct answer: Given the following C# classes: public class
I have the following classes: class Vigil < ActiveRecord::Base after_update :do_something_cool private def do_something_cool
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
Update: This turned into a blog post, with updated links and code, over at
[Update]: my initial example doesn't reflect my problem. Updated the sample, hopfully it is
I have a table which is updated with ajax and after update it if
As you might be aware an update to visual studio 2005 was auto updated
I need to update a record in the datastore, but instead of updated record
I have got several classes looking like the one below, and I need to

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.