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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:30:11+00:00 2026-05-31T18:30:11+00:00

This is my situation, very much simplified. My classes; public class ClassBase { [Key]

  • 0

This is my situation, very much simplified.

My classes;

public class ClassBase
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
}

public class ClassMiddle1 : ClassBase
{

}

public class ClassMiddle2 : ClassBase
{
    public Guid Token { get; set; }
}

public class ClassA : ClassMiddle1
{
    public string UserId { get; set; }
    public string Username { get; set; }
}

public class ClassB : ClassMiddle2
{
    public string Username { get; set; }
}

And my OnModelCreating;

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<ClassBase>()
        .Map(m => {
            m.Properties(p => new { p.Id});
            m.ToTable("TableBase");
        });

    modelBuilder.Entity<ClassMiddle1>()
        .Map<ClassMiddle1>(m =>
        {
            m.Properties(p => new { });
            m.ToTable("TableBase");
        });

    modelBuilder.Entity<ClassMiddle2>()
        .Map<ClassMiddle2>(m =>
        {
            m.Properties(p => new { p.Token });
            m.ToTable("TableBase");
        });

    modelBuilder.Entity<ClassA>()
        .Map<ClassA>(m =>
        {
            m.Properties(p => new
            {
                p.UserId,
                p.Username
            });
            m.ToTable("TableA");

        });

    modelBuilder.Entity<ClassB>()
        .Map<ClassB>(m =>
        {
            m.Properties(p => new
            {
                p.Username
            });
            m.ToTable("TableB");

        }).Property(p => p.Username).HasColumnName("User");

}

This works fine but the Discriminator column is by default Discriminator, NVARCHAR(128). I read that it is possible to define this column myself using something like below.

m.Requires("ClassType").HasValue(1);

I turned my possibilities inside out but all times running into a dead end. Anyone having a suggestion how to do it?

I will end with another question. As our hierarchy pretty much are as above but even more derivated classes like C, D, E, F and so on to… say P. We found out that EF are making this incredibly big database query (~150K). Anyone else ran into this scenario?

I am hoping with changing Discriminator to at least minimize this. By that I say we have a very neat class hierarchy but an ugly query set.

  • 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-31T18:30:12+00:00Added an answer on May 31, 2026 at 6:30 pm

    Late answer how the actual solution went. Only writing it down here because the documentation around this was not that easy to find.

    My solution ended up like below…

    modelBuilder.Entity<ClassBase>()
            .Map(m => {
                ...
                m.Requires("Discriminator").HasValue(1)
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have somehow misconfigured fingers. This leads to a very annoying situation. I select
I have this situation: { float foo[10]; for (int i = 0; i <
This situation arises from someone wanting to create their own pages in their web
In this situation I am trying to perform a data import from an XML
In this situation I have two models, Comment and Score. The relationship is defined
I ran across this situation this afternoon, so I thought I'd ask what you
Look at this situation: www.websitea.com displays an img tag with a src attribute of
I've come upon this situation a few times before. I wish to reference a
I frequently encounter this situation in my VB6 applications Private Sub DoSomething On Error
I have this situation where I want to display a list of Administration objects

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.