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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:09:15+00:00 2026-05-23T15:09:15+00:00

I am making a website on asp.net MVC and I am using a repository

  • 0

I am making a website on asp.net MVC and I am using a repository interface to use repository in memory and using database.

I have all my relationships fixed up, what I mean is for example when I have one contact than he have addresses, so.. when I add one address to this contact automatically fixup the relashionship for address.contact points to the contact, and I leave the properties virtual for entity framework create the proxies then using database repository.

My question starts here:

I have one query like this:

return query.Where(c => c.UserID == clientId)
                         .Include(c => c.AssignedProjects)
                         .Select(c => new UserDetailsData<Client>
                         {
                             User = c,
                             IssuesCount = c.IssuesReported.Count()
                         }).Single();

that uses include.
If I remove the Select assignedProjects will contain the Projects for this client, but when I include Select AssignedProjects is null and anonymous object is fine but.. user don’t contain any AssignedProjects.

In memory I can do that, but using EF I cannot.

The final graph that I want is.. The user with clientID having collection AssignedProjects with his projects and creates anonymous object with User (with the collection) and IssuesCount passing to a view to show the AssignedProjects, The User information and the number of issues that client reported..

Anyone know how I can resolve this?

  • 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-23T15:09:16+00:00Added an answer on May 23, 2026 at 3:09 pm

    You can try this:

    return query.Where(c => c.UserID == clientId)
                .Select(c => new UserDetailsData<Client>
                {
                    User = c,
                    AssignedProjects = c.AssignedProjects,
                    IssuesCount = c.IssuesReported.Count()
                }).Single();
    

    Although you are not really interested in the AssignedProjects property of the type you project into it will populate the User.AssignedProjects property too. This leverages “relationship span”, a feature in EF which automatically builds up navigation properties of objects loaded into the context.

    Be aware that this really relies on the fact that you load the objects into the context. If you disable tracking – for instance by using AsNoTracking() in your query – it doesn’t work anymore.

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

Sidebar

Related Questions

I have an Asp.net MVC website and for that I will making a lighter
I am currently in the process of making a new ASP.net MVC website, and
I have simple jQuery Mobile site created using asp.net mvc 2 and uses basic
If another website is making a POST to my ASP.NET MVC 2 site, how
i'm trying to use OutputCaching in my ASP.NET MVC website. Problem is, when i
I am making a website in asp.net. So my question is, which database is
i am making a website using asp.net and C# and well i got stuck
I am making a website in ASP.NET and want to be able to have
Im making a asp.net(2.0) website. I have defined two resource files in the App_GlobalResources
I'm using LinqToSql classes in an ASP.NET website and let's say I have an

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.