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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:14:51+00:00 2026-06-12T10:14:51+00:00

I am converting a SQL query to LINQ that creates a left join with

  • 0

I am converting a SQL query to LINQ that creates a left join with 1-to-1 mapping, and it has to be in Method Syntax. I have been pulling off my hair trying to accomplish this to no veil. I can do it in Lambda Syntax. Below is the example query I am trying to run. They are not actual code. Would someone point out what I am doing wrong?

SQL:

SELECT item.*, item_status.*
FROM item
LEFT JOIN item_status 
    ON item.ID = item_status.itemID
    AND item_status.FLAGGED = true
WHERE item.published_date > "2008-06-19"

LINQ:

var linq_query = (
    from selected_item in item
    join selected_item_status in item_status
        on selected_item.ID equals item_status.itemID into joined
    from item_status in joined.DefaultIfEmpty()
    where item_status.FLAGGED = true
    select new {selected_item, selected_item_status}).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-06-12T10:14:53+00:00Added an answer on June 12, 2026 at 10:14 am

    The join ... into becomes a GroupJoin and the second from becomes a SelectMany:

    var linq_query = Item
        .GroupJoin(
            item_status.Where(x => x.selected_item_status.FLAGGED), // EDIT: Where clause moved here.
            selected_item => selected_item.ID,
            selected_item_status => selected_item_status.itemID,
            (selected_item, joined) => new
            {
                selected_item,
                statuses = joined.DefaultWithEmpty(),
            })
        .SelectMany(x => x.statuses.Select(selected_item_status => new
        {
            x.selected_item,
            selected_item_status,
        }))
        // EDIT: Removed where clause.
        .ToList();
    

    It looks like the Where makes the left outer join unnecessary, as null statuses will be filtered out anyway.

    EDIT: No, upon reviewing the SQL it looks like your LINQ query is slightly incorrect. It should be:

    var linq_query = (
        from selected_item in item
        join selected_item_status
            in (
                from status in item_status
                where status.FLAGGED
                select status)
            on selected_item.ID equals item_status.itemID into joined
        from item_status in joined.DefaultIfEmpty()
        select new {selected_item, selected_item_status}).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that needs a property set inside a LINQ-to-SQL query. My
I have a linq to sql query that returns some orders with non zero
Could somebody assist me in converting a sql query into LINQ, i'm pretty handy
Can someone hep me converting the following SQL query into LINQ? select convert(varchar(10),date,110) as
hi guys i am stuck converting below sql to LINQ query. all i want
I am having problem converting my SQL query to LINQ. How would you create
Can someone help me converting the following SQL Query into LINQ expression? select student.StudentID,
I need help converting the following SQL query into LINQ: select s.teacherid,t.lastname,t.firstname,t.title,t.grade, count(s.TeacherID) from
I have an Editable Data grid which is pulling data from a SQL query
I have a query that works perfectly in SQL, but I'm having the damnedest

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.