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

  • Home
  • SEARCH
  • 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 7184181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:08:51+00:00 2026-05-28T18:08:51+00:00

I have an Abstract type called Product, and five Types that inherit from Product

  • 0

I have an Abstract type called Product, and five “Types” that inherit from Product in a table per type hierarchy fashion as below:

Table Per Type

I want to get all of the information for all of the Products, including a smattering of properties from the different objects that inherit from products to project them into a new class for use in an MVC web page. My linq query is below:

     //Return the required products
    var model = from p in Product.Products
                where p.archive == false && ((Prod_ID == 0) || (p.ID == Prod_ID))
                select new SearchViewModel 
                    {
                        ID = p.ID,
                        lend_name = p.Lender.lend_name,
                        pDes_rate = p.pDes_rate,
                        pDes_details = p.pDes_details,
                        pDes_totTerm = p.pDes_totTerm,
                        pDes_APR = p.pDes_APR,
                        pDes_revDesc = p.pDes_revDesc,
                        pMax_desc = p.pMax_desc,
                        dDipNeeded = p.dDipNeeded,
                        dAppNeeded = p.dAppNeeded,      

                        CalcFields = new DAL.SearchCalcFields
                        {
                            pDes_type = p.pDes_type,
                            pDes_rate = p.pDes_rate,
                            pTFi_fixedRate = p.pTFi_fixedRate 
                        }
                    }

The problem I have is accessing the p.pTFi_fixedRate, this is not returned with the Products collection of entities as it is in the super type of Fixed. How do I return the “super” type of Products (Fixed) properties using Linq and the Entity Framework. I actually need to return some fields from all the different supertypes (Disc, Track, etc) for use in calculations. Should I return these as separate Linq queries checking the type of “Product” that is returned?

  • 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-28T18:08:52+00:00Added an answer on May 28, 2026 at 6:08 pm

    This is a really good question. I’ve had a look in the Julie Lerman book and scouted around the internet and I can’t see an elegant answer.

    If it were me I would create a data transfer object will all the properties of the types and then have a separate query for each type and then union them all up. I would insert blanks into the DTO properies where the properties aren’t relevant to that type. Then I would hope that the EF engine makes a reasonable stab at creating decent SQL.

    Example

    var results = (from p in context.Products.OfType<Disc>
            select new ProductDTO {basefield1 = p.val1, discField=p.val2, fixedField=""})
             .Union(
            from p in context.Products.OfType<Fixed>
            select new ProductDTO {basefield1 = p.val1, discField="", fixedField=p.val2});
    

    But that can’t be the best answer can it. Is there any others?

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

Sidebar

Related Questions

I have a vector that holds pointers to abstract type Rock : vector<Rock*> rocks;
I have a scenario where a class called Comment references an abstract type called
I have a custom base type called MyEntityBase for the superclass of the types
Let's say I have an abstract parent class called shape, and that there are
I have a public class FriendMaps extends MapActivity that gets called from a menu
I am working on a project, and I have a generic abstract type that
Ok, so I have an abstract class called Product. I have 3 tables called
So I have an abstract data type called RegionModel with a series of values
I have an abstract class: type TInterfaceMethod = class abstract public destructor Destroy; virtual;
I have an abstract base class and derived class: type TInterfaceMethod = class public

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.