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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:10:12+00:00 2026-05-22T20:10:12+00:00

I Supplier class: public class Supplier { …. …. …. } I have also

  • 0

I Supplier class:

public class Supplier {
    ....
    ....
    ....
}

I have also Subcontractor class and Subcontractor is a Supplier:

public class Subcontractor:Supplier {
    ....
    ....
    ....
}

In my db I have Suppliers table with data and another table with id field which is act as foreign key to suppliers table and I have in there also the subcintractor data.

In the entity framework edmx file I declared the inheritance relation:
inheritance

Now I want to gett all the suppliers which are not subcontractors so I am doing:

context.Suppliers.OfType<Supplier>();

But this returns also the subcontractors..

How can I get only the Suppliers that are not subcontractors?

  • 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-22T20:10:13+00:00Added an answer on May 22, 2026 at 8:10 pm

    Give this a try:

    context.Suppliers.Where(s => !(s is Subcontractor));
    

    Edit

    If you have more than one class which derives from Supplier the only option with LINQ to Entities seems to be something like:

    context.Suppliers.Where(s => !(s is Subcontractor) 
                              && !(s is DerivedClass2)
                              && !(s is DerivedClass3)); // etc.
    

    Entity SQL supports an ONLY keyword which allows to query for a specific type. But a corresponding counterpart is not available as LINQ operator.

    Here is an implementation of an OfTypeOnly<TEntity> operator but it makes heavy use of metadata information and manual expression building and might be overkill in simple scenarios.

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

Sidebar

Related Questions

Let's say I have: public class Fruit { public static List<String> Suppliers { get;
We are using Nhibernate as our data access layer. We have a table of
I have a Supplier entity, each Supplier object may reference another Supplier object as
I have a generic class which represents a fragment of text. That fragment of
I have a simple loginform based on the following modelitem public class LogOnModelItem {
I have ThirdParty entity and two derived entities: Supplier and Customer. I have another
We have a supplier who provides a library for access to their hardware. Unfortunately,
The issue I have is as follows: My company's supplier gives us an Access
I have a bunch of generated functions from a supplier's tool are required to
We have a product that uses a Reference from a 3rd party supplier. With

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.