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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:30:26+00:00 2026-06-15T00:30:26+00:00

Suppose I have a class Parent, with two subclasses, AChild and BChild. I have

  • 0

Suppose I have a class Parent, with two subclasses, AChild and BChild. I have these mapped to a single table using Entity Framework 5.0.0 on .NET 4.5, using TPH.

public abstract class Parent {
    public string Type { get; set; } // Column with this name in DB is discriminator.
    public string Status { get; set; }
}

public class AChild : Parent {
    // Other stuff.
}

public class BChild : Parent {
    // Other stuff.
}

The code to configure the mapping:

class ParentConfiguration : EntityTypeConfiguration<Parent> {
    Map((EntityMappingConfiguration<AChild> mapping) => mapping
        .Requires("Type")
        .HasValue("A"));
    Map((EntityMappingConfiguration<BChild> mapping) => mapping
        .Requires("Type")
        .HasValue("B"));
}

I have a need to run a query that returns both AChild and BChild objects. However, it needs to filter ONLY the AChild rows by a second column, which in this example I will call Status.

Ideally I would want to do the following:

public IList<Parent> RunQuery() {
    IQueryable<Parent> query =
        this.context.Set<Parent>()
        .Where((Parent parent) => !parent.Type.Equals("A") || parent.Status.Equals("Foo"))
        .OrderBy((Parent parent) => parent.Number);
    return query.ToList();
}

This doesn’t work. It insisted on looking for a “Type1” column instead of just letting both the discriminator and a “Type” property be mapped to the same “Type” column.

I know of the “OfType” extension method that can be used to completely filter down to one type, but that’s too broad a brush in this case.

I could possibly run multiple queries and combine the results, but the actual system I’m building is doing paging, so if I need to pull back 10 rows, it gets messy (and inefficient) to query since I’ll either end up pulling back too many rows, or not pull back enough and have to run extra queries.

Does anyone have any other thoughts?

  • 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-06-15T00:30:27+00:00Added an answer on June 15, 2026 at 12:30 am

    There are few problems. First of all you cannot have discriminator mapped as a property. That is the reason why it is looking for Type1 column – your Type property results in second column because the first one is already mapped to .NET types of your classes. The only way to filter derived types is through OfType.

    The query you want to build will be probably quite complex because you need to query for all Bs and concatenate them with result of query for filtered As. It will most probably not allow you to concatenate instances of Bs with As so you will have to convert them back to parent type.

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

Sidebar

Related Questions

I'm trying out Entity Framework Code first CTP4. Suppose I have: public class Parent
Suppose I have two classes like so: class Parent def say I am a
Suppose I have these two objects: public class Object1 { string prop1; string prop2;
Supposed I have two classes like this: public class Parent { public string Id
Suppose i have this structure of elements: <div class=parent> <div class=something1> <div class=something2> <div
Suppose I have two classes (one a parent and one a subclass). How do
Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
Suppose I have two Classes, A and B. The A class is defined as
Suppose I have a parent class that implements a protocol: @interface GameViewController : UIViewController<GamePrizeDelegate>
Let's suppose I have a parent class in PHP like this: class A {

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.