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

The Archive Base Latest Questions

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

This is a spin off from another question I posted a few days ago

  • 0

This is a spin off from another question I posted a few days ago that was successfully answered but it really didn’t get into the underlying issue I was having but wasn’t able to express fully in my original query.

I have a table Product. Product is related to ProductDescription in a one-to-many relationship. ProductDescription can have more than one row for each product. It will have multiple rows if there are multiple translations for the description of the product. Product has a many-to-one relationship with Language. Language has a language code (en, es, etc.) as well as a LanguageId (found in ProductDescription as well).

I want to give my users the ability to request a product and further tell the application to only return descriptions for that product in a specific language.

The problem I’m having is that I understand I need to use projection to accomplish the task in the 3rd paragraph of this question. Something like this:

    var query = inventoryRepository.Products
                        .Where(wherePredicate)
                        .Select( a=> new Product
                        {
                            ProductDescriptions = inventoryRepository.ObjectContext.ProductDescriptions
                               .Where(a => a.Languages.AlternateCode.Equals("en", StringComparison.CurrentCultureIgnoreCase))
                        });

However I have about 15 properties in the Products table as well as 4 other child tables of Products that need to be loaded for the result set in addition to just the languages piece. Is there any way for me to do eager loading AND projection so that I don’t have to go through and map all of these properties and children objects manually? Here is where my code stands right now:

var query = inventoryRepository.ObjectSet
                    .Include("ProductDescriptions")
                    .Include("ProductAllowedWarehouses")
                    .Include("ProductToCategories")
                    .Include("PriceLevels")
                    .Include("AttachmentAssociations.Attachment").AsExpandable()
                    .Where(wherePredicate);

No Select necessary which is really nice. Once I change ProductDescriptions to a projection I add a Select and then I don’t get any of the other properties / children populated for free.

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

    I would read this blog about projections+eager loading. You are going to run into issues when it comes to the eager loading. Recommendation is to use a .Any and perform a sub select.

    Why can’t you just add a filter/where on ProductDescriptions?

     var query = inventoryRepository.ObjectSet
                    .Include("ProductDescriptions")
                    .Include("ProductAllowedWarehouses")
                    .Include("ProductToCategories")
                    .Include("PriceLevels")
                    .Include("AttachmentAssociations.Attachment").AsExpandable()
                    .Where(wherePredicate)
                    .Where(a=>a.ProductDescriptions.Languages.AlternateCode.Equals("en", StringComparison.CurrentCultureIgnoreCase);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've asked a question similar to this but thought I would ask a more
This one is making my head spin. Just when I think I got it,
SO this is a bit of an odd request but hoping someone on here
This is my fist stackoverflow post so please be gentle with me! I'm sure
I would like to remove all CSS background images for a given element and
I have the following method within my TcpServer private void Receive(ZClient client) { NetworkStream
I am going to create a gallery view where the user shall switch between
Is there a way when clicked on a button in a C# Windows App,
I'm having trouble with a processing thread in C#. Basically the thread manages chat
I have a JSpinner using a SpinnerDateModel which has a start at Jan 1,

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.