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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:31:53+00:00 2026-05-28T23:31:53+00:00

I have been looking for a solution for days now. I have eight entities

  • 0

I have been looking for a solution for days now.

I have eight entities in my application, a base and seven entities that inherits from this base entity. Some of the child entities have same properties.

public class LogEntry(){
    public int LogEntryId{get;set;}
    public string ...
}

public class TestEntry : LogEntry{
   ....
   public string SomeProperty{get;set;} //SomePropertyThatIsNotInBaseClass
   ....
}
public class XEntry : LogEntry{
   ....
   public string SomeProperty{get; set;}
   ....
}

I am trying to filter base entity by this SomeProperty. I am trying to a query like

var value = Db.LogEntry.Where(i=>i.SomePropery == "some string");

It is not allowed. I can only getwhat I want by

IQueryable<LogEntry> first = Db.LogEntry.OfType<TestEntry>.Where(i=>i.SomeProperty == "...");
IQueryable<LogEntry> second = Db.LogEntry.OfType<XEntry>.Where(i=>i.SomeProperty == "...");
...

And concatenate them at the end. Is there more clever way to do than this method? Extension methods etc…

Any help would be appreciated.

  • 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-28T23:31:54+00:00Added an answer on May 28, 2026 at 11:31 pm

    Edit

    Looking at your example more closely, I don’t think what you are trying to do is possible. If you are writing a query against the BASE entity type, then you can only query fields that are defined in the base type.

    Since “SomeProperty” is not defined in LogEntry, you cannot write this query:

    var logEntries = db.LogEntry.Where(r => r.SomeProperty == "foo");
    

    Because SomeProperty is not defined in the LogEntry class.

    If you want to write queries against the base class then you need to do something like the following:

    public class TPTContext : DbContext
    {
        public TPTContext() : base("name=TPT")
        { }
    
        public DbSet<BillingDetail> BillingDetails { get; set; }
    }
    
    public abstract class BillingDetail
    {
        public int BillingDetailId { get; set; }
        public string Owner { get; set; }
        public string Number { get; set; }
    }
    
    [Table("BankAccounts")]
    public class BankAccount : BillingDetail
    {
        public string BankName { get; set; }
        public string Swift { get; set; }
    }
    
    [Table("CreditCards")]
    public class CreditCard : BillingDetail
    {
        public int CardType { get; set; }
        public string ExpiryMonth { get; set; }
        public string ExpiryYear { get; set; }
    }
    

    I wrote the following query against the base class:

    TPTContext db = new TPTContext();
    
    var allAccounts = db.BillingDetails.Where(b => b.Owner == "boran");
    var bankAccounts = allAccounts.OfType<BankAccount>();
    var creditCards = allAccounts.OfType<CreditCard>();
    

    Everything seems to work fine for me.

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

Sidebar

Related Questions

I have been looking for a solution to this issue for a few days
I have been looking around for a solution for this problem that works across
Have been looking at the MVC storefront and see that IQueryable is returned from
I've been searching for a solution to this issue for a few days now.
I've been battling with this issue for a couple of days now. I have
I have been looking for an effective solution to remove duplicates from a C++
I have a problem with this code. I have been looking for the solution
I have been looking for a solution to this problem for ages. I have
I have been looking for documentation related to interacting with MSPaint from the command
I have been looking for a solution, and haven't been lucky to find one.

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.