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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:04:05+00:00 2026-06-17T02:04:05+00:00

In a current MVC4.0 project I am using Entity Framework 4.1 Database first model.

  • 0

In a current MVC4.0 project I am using Entity Framework 4.1 Database first model.

Part of this structure includes the following tables

compGroupData
SurveyData
SecondaryData

compGroupData and SurveyData are not joined in the database

SecondaryData is joined to SurveyData on a one to one relationship via a Foreign Key SurveyData.surveydatakey = SecondaryData.surveydatakey

In my project I have a class ComparisonWithData defined as:

public class ComparisonWithData
{
    public compGroupData compgrp { get; set; }
    public SurveyData surveydata { get; set; }
    public ComparisonWithData()
    {
        compgrp = new compGroupData();
        surveydata = new SurveyData();
    }
}

This gives me a result set for a specific Comparison group and the data that matches this.

In the past I have retrieved the data for this via the following query:

    List<ComparisonWithData> comparisonwithdata  = ((from compgrp in db.compGroupDatas
                       where compgrp.grpYear == rptyear && compgrp.CompGroupID == ccompgrp.CompGrpID
                       join surveydata in db.SurveyDatas on new { compgrp.companyid, SurveyYear = (Int32)compgrp.SurveyYear } equals new { companyid = surveydata.companyid, SurveyYear = surveydata.surveyyear }
                       select new ComparisonWithData
                       {
                           compgrp = compgrp,
                           surveydata = surveydata,


                       }
                       )).ToList();

With a recent change in data I now need to also reference the SecondaryData but due to the number of records really need this to load Eagerly instead of Lazy. (Lazy loading during the loop results in thousands of DB calls)

I have looked at using the “Include” method on surveydata as well as casting the initial query as an ObjectQuery and doing the Include off that.

The first method doesn’t eager load and the second method seems to always return a null object as a result.

Is there a method to Eager load the SecondaryData for SurveyData or should I be looking at a different approach all together.

My only restriction on this is that I can’t go up to EF5 because of a limitation we have on .Net 4.5

Any assistance would be greatly appreciated.

Thank you.

  • 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-17T02:04:06+00:00Added an answer on June 17, 2026 at 2:04 am

    You could try to project into an anonymous object first and use also SecondaryData in that projection, materialize this result and then project again into your final result object. Automatic Relationship Fixup that the EF context provides should populate the navigation property surveyData.SecondaryData of your ComparisonWithData object (as long as you don’t disable change tracking in your query):

    var data = (( // ... part up to select unchanged ...
               select new // anonymous object
               {
                   compgrp = compgrp,
                   surveydata = surveydata,
                   secondarydata = surveydata.SecondaryData
               }
               )).AsEnumerable();
               // part until here is DB query, the rest from here is query in memory
    
    List<ComparisonWithData> comparisonwithdata =
               (from d in data
               select new ComparisonWithData
               {
                   compgrp = d.compgrp,
                   surveydata = d.surveydata
               }
               )).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Current situation: I have a database with following structure: Product Category (contains column product_id)
I'm working on Asp.net MVC4 project using Visual Studio 2012. When there's an error
I have a MVC4 project in VS2012. How can i debug the current open
Current project is an Mvc4 application, I had Ioc working and recently it just
I am using Data Annotations for Model validation in MVC4 and am currently using
first of all the current state: I have a MVC4 webapplication (online calculator) with
Current Application Server Configuration: IIS 6.0 Windows 2003 Server Standard Edition SP2 .NET Framework
I have a problem in my MVC4 project in visual studio 2012. I build
I want to use Role without any provider in asp.net MVC4 project. I success
I have a problem that I suppose comes from my ASP.NET MVC project using

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.