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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:50:02+00:00 2026-05-17T16:50:02+00:00

I am having a lot of trouble with ‘base types’ in the Code Only

  • 0

I am having a lot of trouble with ‘base types’ in the Code Only model of the Entity Framework. I am having a lot of trouble with ‘base types’ in the Code Only model of the Entity Framework.

When I try to run this code using a DbContext with a DbSet<Template>, I get the following error.

A The navigation property ‘Flags’ is mapped to two different join tables ‘page.flags’ and ‘template.flags’. Only one mapping of the navigation property may exist

What this says to me is that I cannot map inherited properties. This is quite breaking to a lot of object oriented code design. Is there a known remedy? I realize I can make Layout non-abstract, and have a backing for it, but it’s very obvious this is not the intention of the domain model. The abstract class is a foundational base, not the stored model.

I would like to add, if I put the IList<Flag> in the Template class, this code runs. The Id field still works, even through inheritance. I do not understand why this is happening. Can someone enlighten me?

public abstract class Layout
{
    public virtual int Id
    {
        get;
        set;
    }

    public virtual IList<Flag> Flags
    {
        get;
        set;
    }
}

public class Template : Layout
{
    public virtual string Name
    {
        get;
        set;
    }
}

public class Page: Layout
{
}

public class LayoutConfiguration : EntityConfiguration<Layout>
{
    public LayoutConfiguration()
    {
        HasKey(u => u.Id);
        Property(u => u.Id).IsIdentity();

        MapHierarchy().Case<Page>(c => new
        {
            c.Id
        }).ToTable("Pages");

        MapHierarchy().Case<Template>(c => new
        {
            c.Id,
            c.Name
        }).ToTable("Templates");
    }
}
public class TemplateConfiguration : EntityConfiguration<Template>
{
    public TemplateConfiguration()
    {
        Property(o => o.Name).HasMaxLength(64).IsUnicode();

        HasMany(u => u.Flags).WithOptional()
            .Map("template.flags",
            (template, flag) => new {
                Template = template.Id,
                Flag = flag.Id
            });

        MapSingleType(c => new {
            c.Id,
            c.Name
        }).ToTable("templates");
    }
}

public class PageConfiguration : EntityConfiguration<Page>
{
    public PageConfiguration()
    {
        HasMany(c => c.Flags).WithOptional()
            .Map("page.flags",
            (page, flag) => new
            {
                Page = page.Id,
                Flag = flag.Id
            });
    }
}
  • 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-17T16:50:03+00:00Added an answer on May 17, 2026 at 4:50 pm

    When you use base type for your Template entity, you also have to model this inheritance in mapping. It means that you have to write configuration for Layout which will map Id and Flags and configuration for Template which will map Name. There is several approaches of mapping inheritance in EF. You should probably check Table per Hiearchy.

    Edit: Based on your comment you are looking for Table per Class + examples for CTP4.

    Edit2: Ok. I tested your scenario with navigation property defined in abstract parent class and it really doesn’t work if you are trying to map it to multiple tables.

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

Sidebar

Related Questions

No related questions found

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.