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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:49:58+00:00 2026-05-21T20:49:58+00:00

I have a Profile class that has a father property which self references to

  • 0

I have a Profile class that has a father property which self references to itself, I want to load a profile together with its fathers profile in one sql join statement

Select * FROM profile left join profile as father on profile.fatherid = father.id where profile.id = 650

So i created the following linq statement, but instead of running the sql statement about it runs the following statements

select * from profiles

select * from profiles where id = 650

Then in memory it groups them together, but obviously i would not want to load the whole database.

    private class Result
    {
        public Profile Profile { get; set; }
        public IEnumerable<Profile> Fathers { get; set; }
    }
    private Result MapFather(Profile p, IEnumerable<Profile> father)
    {
        return new Result() {Profile = p, Fathers = father.DefaultIfEmpty()};
    }

   var profiles = from p in db.Profiles where p.ID.Equals(650) select p;
   var fathers = from f in db.Profiles select f;
   var groupJoin = profiles.GroupJoin(fathers,
                                        p => p.FatherID, 
                                        f => f.ID, 
                                        MapFather).ToList();
  • 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-21T20:49:59+00:00Added an answer on May 21, 2026 at 8:49 pm

    Your call to GroupJoin() is getting the IEnumerable version because of your call to MapFather is a Func<,> instead of Expression>. Therefore the calls to profiles and fathers are being executed before the GroupJoin.

    Try inlining MapFather():

    var groupJoin = profiles.GroupJoin(fathers,
                                        p => p.FatherID, 
                                        f => f.ID, 
                                        (p, fathers) => new Result() {Profile = p, Fathers = father.DefaultIfEmpty()}).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DLL that I want to profile.. I tried to use Very
I have user profile model with M2M field class Account(models.Model): ... friends = models.ManyToManyField('self',
If I have a maven profile activated by the presence of a property, how
I have a database that hold's a user's optional profile. In the profile I
This is something that I have always wondered about, but never bothered to profile.
For .net 3.5 SP1, Microsoft have the new client profile which installs only a
Anyone have experience with adding a ReSharper profile to the VS2008 solution and share
Most of my users have email addresses associated with their profile in /etc/passwd .
How do Window's programmers profile their native C++ code? On Unix/Linux you have gprof
This is pretty weird. I have my Profiler open and it obviously shows that

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.