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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:48:18+00:00 2026-05-23T17:48:18+00:00

I have a problem in making a left/right join with linq. I have lets

  • 0

I have a problem in making a left/right join with linq.

I have lets say

public class Customer
{
  prop string CustomerId { get; set; }
  prop string LanguageGuid { get; set; }
}

public class ReadOnlyCustomer
{
  prop string CustomerId { get; set; }
  prop string LanguageGuid { get; set; }
}

I have a lot of customers in the ReadonlyCustomer table.
In my case I dont have all the customers in customer table.
So I cant use the Join, i dont what the inner join.
I need the left or right join.

var test = db.Customer.Join(db.ReadOnlyCustomer, p => p.CustomerId, o => o.CustomerId, (c, o) => new ReadOnlyCustomer() { CustomerId = c.CustomerId, LanguageGuid = o.LanguageGuid ?? c.LanguageGuid });

At this point, I get a null pointer, because the query cant join on a null ref.

How can I do a left join equal to sql left join, where I get NULL for value that does not exist in the datasource.

This needs to be in lampda not comprehensing syntax like (from o in ….)

// dennis

  • 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-23T17:48:20+00:00Added an answer on May 23, 2026 at 5:48 pm

    You need to use GroupJoin, sometimes in conjunction with a call to DefaultIfEmpty() afterwards to give a single null value for the group. You can then use SelectMany() to end up with one result per pair, noting that one of the values in the result may be null.

    For example:

    // Note: can only do a *left* join, so "bigger" table comes first
    var test = db.ReadOnlyCustomer
                 .GroupJoin(db.Customer,
                            p => p.CustomerId,
                            o => o.CustomerId,
                            (p, os) => new { p, os = os.DefaultIfEmpty() })
                 // Each pair may have multiple os here
                .SelectMany(pair => pair.os.Select(o => new { pair.p, o }))
                // Flattened, but o may be null
                .Select(pair => new ReadOnlyCustomer {
                          CustomerId = pair.p.CustomerId,
                          LanguageGuid = o != null ? o.LanguageGuid ?? p.LanguageGuid
                                                   : p.LanguageGuid
                        });
    

    (Out of interest, why does this need to be in lambda syntax rather than as a query expression? Typically joins of all kinds are simpler to express in query expressions.)

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

Sidebar

Related Questions

Here is my problem. I have created a pretty heavy readonly class making many
My only problem is making them line up three-across and have equal spacing. Apparently,
I am making an application with Java Swing and i have a problem. I
I have a very big problem. I am making a CRM (Costumer Relationship Management)
I have a tiny (rikiki) problem in SWT ... I am making a small
I have a problem with a multibinding: <Canvas> <local:SPoint x:Name=sp Width=10 Height=10> <Canvas.Left><!-- irrelevant
I'm making Braid. I have a class Wall that prevents that an object goes
I have a problem on a program I'm making that I honestly can't find
I have a problem with IE (what a surprise). I am making an issue
I have problem in some JavaScript that I am writing where the Switch statement

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.