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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:58:50+00:00 2026-05-25T19:58:50+00:00

The following LINQ to Entities query (using EF 4.1 Code-First), is supposed to create

  • 0

The following LINQ to Entities query (using EF 4.1 Code-First), is supposed to create a list of viewmodels based on Campaigns and Users. I have eager-loaded Category property of each campaign so that each campaign should have its Category reference property filled with appropriate data. But it seems like this eager-loading is lost somewhere, thus I cannot access categories like: campViewModels[0].Campaign.Category. It’s always null.

var campViewModels = ctx.Campaigns
.Include(c => c.Category)
.Where(c => c.Title.Contains(searchText)).Join(
    ctx.Users,
    c => c.CampaignId,
    u => u.CampaignId,
    (c, u) => new {c, u})
    .GroupBy(cu => cu.c)
    .Select(g => new CampaignViewModel { Campaign =  g.Key, MemberCount=g.Count()})
    .OrderByDescending(vm => vm.MemberCount)
    .Skip(pageIndex)
    .Take(pageSize)
    .ToList();  

For workaround this problem, I have changed my viewmodel definition and to have CategoryText property and filled it in my query:

Select(g => new CampaignViewModel { Campaign =  g.Key, MemberCount=g.Count(), CategoryText = g.Key.Category.Title})  

But
I’m curious to find out what prevented the explicit loading of categories?

  • 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-25T19:58:50+00:00Added an answer on May 25, 2026 at 7:58 pm

    Include is ignored when you project to a new type, use a join, or a group by

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

Sidebar

Related Questions

I have the following query of linq to entities. The problem is that it
I have a problem with the following Linq query using Entity Framework: from o
If I have the following Linq code: context.Table1s.InsertOnSubmit(t); context.Table1s.InsertOnSubmit(t2); context.Table1s.InsertOnSubmit(t3); context.SubmitChanges(); And I get
I have the following Linq to SQL query, in which I'm trying to do
I have this project set up with EF4 and I'm using LINQ to Entities
I have an SQL query (generated by LINQ to Entities) which is roughly like
I have following Linq query/function in my MVC3 application. public AuditTrail GetNamesAddressesEmployers(long registryId ,
Starting with the following LINQ query: from a in things where a.Id == b.Id
Is there a way to do the following using LINQ? foreach (var c in
I am following a VB tutorial to do some HTML manipulation using LINQ It

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.