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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:00:25+00:00 2026-05-30T01:00:25+00:00

I have the below public class Person { // Properties public string Name {

  • 0

I have the below

public class Person
    { 
        // Properties
        public string Name { get; set; }
        public string Area { get; set; }
        public string Gender { get; set; }
        public int Age { get; set; }

        public List<Person> GetPersonData()
        {
            List<Person> personLst = new List<Person>  {
           new Person { Name="Shashidhar Niketani", Age=20, Gender="Male" , Area = "Assam"},
           new Person { Name="Ahmed Ali Khan", Age=25 ,Gender="Male", Area = "Assam" },
           new Person { Name="S. Mirja", Age=20, Gender="Female", Area = "Assam"},
           new Person { Name="Neru Kumar", Age=18, Gender="Female", Area = "Colombo"},
           new Person { Name="Chidam P", Age=19, Gender="Male", Area = "Colombo"},
           new Person { Name="H Kontala", Age=19, Gender="Male", Area = "Bombay"},
           new Person { Name="Priya Pankhraj", Age=23, Gender="Female", Area = "North Punjab"},
             new Person { Name="Ambla", Age=20, Gender="Female", Area = "Madras"},
           new Person { Name="H Kontala", Age=25, Gender="Male", Area = "Bombay"},
           new Person { Name="Sirisha Chalukuri", Age=30, Gender="Female", Area = "Bombay"}};
            return personLst;
        }

        public override string ToString()
        {
            return string.Format("Patient Name: =  {0} , Age:= {1}, Gender:= {2}, Area: = {3}", Name, Age, Gender, Area);
        }

    }

    public class Hobbies
    {
        public string Owner { get; set; }
        public string HobbyName { get; set; }

        public List<Hobbies> GetHobbies()
        {
            List<Hobbies> hobbyList = new List<Hobbies>  {
           new Hobbies { Owner="Sirisha Chalukuri", HobbyName = "Singing"},
           new Hobbies { Owner="Priya Pankhraj", HobbyName = "Cooking" },
           new Hobbies { Owner="S. Mirja", HobbyName="Playing"},
           new Hobbies { Owner="Neru Kumar", HobbyName="Programing"}};
           return hobbyList;
        }
    }

I am trying to perfom a left join

//fetch those records

Person p = new Person();
var personSource = p.GetPersonData();

Hobbies h = new Hobbies();
var hobbySource = h.GetHobbies();

//Left outer join

var res8 = (from person in personSource                       
                        join hobby in hobbySource
                        on p.Name equals hobby.Owner into temp
                        from hobby in temp.DefaultIfEmpty()
                        select new
                            {
                                PersonName = p.Name,
                                PersonAge = p.Age,
                                Gender = p.Gender,
                                LivesIn = p.Area,
                                Hobby = (hobby == null) ? "N/A" : hobby.HobbyName
                            });

But I am not able to get the correct result…All the records are coming as null/non matching records..There are atleast 4 matching records and the rest will be non-matching records…

I am rather looking for like given these two datasource, the result that we will expect if we perform a left join on PersonName and HobbyOwner.

Help needed

  • 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-30T01:00:29+00:00Added an answer on May 30, 2026 at 1:00 am

    When you reference hobby.HobbyName in your select projection, hobby is null when there are no matching hobbies for a person (DefaultIfEmpty returns null for an empty hobby collection). You need to check if hobby is null, and if so assign the Hobby property in the select projection a default value. For example:

    select new
    {
      PersonName = p.Name,
      PersonAge = p.Age,
      Gender = p.Gender,
      LivesIn = p.Area,
      Hobby = (hobby == null) ? "N/A" : hobby.HobbyName
    });
    

    Also, don’t know if it was a typo, but in your query you use p when you should be using person:

    var res8 = (from person in personSource                       
            join hobby in hobbySource
            on person.Name equals hobby.Owner into temp
            from hobby in temp.DefaultIfEmpty()
            select new
            {
             PersonName = person.Name,
             PersonAge = person.Age,
             Gender = person.Gender,
             LivesIn = person.Area,
             Hobby = (hobby == null) ? "N/A" : hobby.HobbyName
             });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have class like below class Person { public string Name{get;set;} public string Surname{get;set;}
I have a simple class as defined below: public class Person { int _id;
I have the following classes: public class Person { public String FirstName { set;
I have this class/object below: public class Person { public string FirstName; public string
I have the code below : public class Anything { public int Data {
I have an entity similar to the below: public class Entity { public List<DateItem>
I have these classes in C# (.NET Framework 3.5) described below: public class Base
I have two classes as below. public class Destination { public Destination() { _StringCollection
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
I have a data structure which is as given below: class File { public

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.