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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:01:50+00:00 2026-05-24T10:01:50+00:00

This is my (simplified) problem. The classes: public class RetailExposure { public int RetailExposureId

  • 0

This is my (simplified) problem.
The classes:

public class RetailExposure
{
    public int RetailExposureId { get; set; }
    public int RetailModelId { get; set; }
}


public class PocRetailExposure : RetailExposure
{
    [NotMapped]
    public string IncidentScore { get; set; }
}

and my OnModelCreating code:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<RetailExposure>().ToTable("dbo.RetailExposure");
        modelBuilder.Entity<RetailExposure>().Map<PocRetailExposure>(p => p.Requires("RetailModelId").HasValue(1).IsRequired());
    }

However when I add a new Exposure record:

        context.RetailExposures.Add(new RetailExposure { RetailModelId = 1 });
        context.SaveChanges();

I get the following error:

System.Data.MappingException: 
(6,10) : error 3032: Problem in mapping fragments starting at line 6:Condition 
member 'RetailExposure.RetailModelId' with a condition other than 'IsNull=False'
is mapped. Either remove the condition on RetailExposure.RetailModelId or remove 
it from the mapping.

What I am trying to do is have a base class ‘RetailExposure’ with derived classes determined from the RetailModelId field. The derived classes contain no properties that are in the database. I seemed to have figured how to configure EF to use RetailModelId as the discriminator, but I still get this error when saving changes.

Any idea on how I need to configure the context to get this to work? Or am I trying to do something that EF does not currently support?

I do realise I could tell EF to just ignore the derived classes entirely, but this is not quite what I want.

  • 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-24T10:01:52+00:00Added an answer on May 24, 2026 at 10:01 am

    Discriminator mustn’t be mapped as property in the entity – it is not supported. Discriminator is just a column in the database and it is mapped to actual entity’s subtype. If you want to have a discriminator as a property you cannot map TPH. Also if your parent entity is not abstract it must have value defined for discriminator as well.

    Something like:

    public class RetailExposure
    {
        public int RetailExposureId { get; set; }
    }
    
    public class PocRetailExposure : RetailExposure
    {
        [NotMapped]
        public string IncidentScore { get; set; }
    }
    
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<RetailExposure>().ToTable("dbo.RetailExposure");
        modelBuilder.Entity<RetailExposure>()
                    .Map<RetailExposure>(p => p.Requires("RetailModelId").HasValue(0))
                    .Map<PocRetailExposure>(p => p.Requires("RetailModelId").HasValue(1));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 classes (simplified for this question): public class Page { public Guid
This is a simplified version of the original problem. I have a class called
I have the following (greatly simplified) classes: public class Customer { [Required(ErrorMessageResourceName=Required, ErrorMessageResourceType=typeof(ResourcesCommon.ValidationStrings))] public
i have the following (simplified) domain classes class Filter { String name static hasMany
My classes look something like this (I include only the relevant properties): public class
I cannot find the solution for this problem, here is the simplified example: On
I have two classes which depend on each other. I've solved this problem before
I'm having trouble trying to get a radius on images. I've simplified my problem
I've needed to get a value back from an anonymous inner class. Inner classes
I can't get the syntax correct for with static variables and c++ classes. This

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.