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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:11:42+00:00 2026-05-11T04:11:42+00:00

Using extension syntax I’m trying to create a left-join using LINQ on two lists

  • 0

Using extension syntax I’m trying to create a left-join using LINQ on two lists that I have. The following is from the Microsoft help but I’ve modified it to show that the pets list has no elements. What I’m ending up with is a list of 0 elements. I assume that this is because an inner-join is taking place. What I want to end up with is a list of 3 elements (the 3 Person objects) with null data filled in for the missing elements. i.e. a Left-Join. Is this possible?

Person magnus = new Person { Name = 'Hedlund, Magnus' }; Person terry = new Person { Name = 'Adams, Terry' }; Person charlotte = new Person { Name = 'Weiss, Charlotte' };  //Pet barley = new Pet { Name = 'Barley', Owner = terry }; //Pet boots = new Pet { Name = 'Boots', Owner = terry }; //Pet whiskers = new Pet { Name = 'Whiskers', Owner = charlotte }; //Pet daisy = new Pet { Name = 'Daisy', Owner = magnus };  List<Person> people = new List<Person> { magnus, terry, charlotte }; //List<Pet> pets = new List<Pet> { barley, boots, whiskers, daisy }; List<Pet> pets = new List<Pet>();  // Create a list of Person-Pet pairs where  // each element is an anonymous type that contains a // Pet's name and the name of the Person that owns the Pet. var query =     people.Join(pets,                 person => person,                 pet => pet.Owner,                 (person, pet) =>                     new { OwnerName = person.Name, Pet = pet.Name }).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. 2026-05-11T04:11:42+00:00Added an answer on May 11, 2026 at 4:11 am

    I think if you want to use extension methods you need to use the GroupJoin

    var query =     people.GroupJoin(pets,                      person => person,                      pet => pet.Owner,                      (person, petCollection) =>                         new { OwnerName = person.Name,                               Pet = PetCollection.Select( p => p.Name )                                                  .DefaultIfEmpty() }                     ).ToList(); 

    You may have to play around with the selection expression. I’m not sure it would give you want you want in the case where you have a 1-to-many relationship.

    I think it’s a little easier with the LINQ Query syntax

    var query = (from person in context.People              join pet in context.Pets on person equals pet.Owner              into tempPets              from pets in tempPets.DefaultIfEmpty()              select new { OwnerName = person.Name, Pet = pets.Name })             .ToList(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 201k
  • Answers 201k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer So many things wrong here... Never NEVER NEVER use dynamic… May 12, 2026 at 8:04 pm
  • Editorial Team
    Editorial Team added an answer Basically you can't, it's more or less impossible to test… May 12, 2026 at 8:04 pm
  • Editorial Team
    Editorial Team added an answer %option nodefault is equivalent to -s May 12, 2026 at 8:04 pm

Related Questions

Using extension syntax I'm trying to create a left-join using LINQ on two lists
How would the following query look if I was using the extension method syntax?
Recently I asked a question about how to clean up what I considered ugly
I am trying to create a class that lets me call methods with a
So I installed Ruby On Rails using the Windows Installer. Now the startup guides

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.