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

  • SEARCH
  • Home
  • 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 799751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:10:52+00:00 2026-05-14T23:10:52+00:00

Given a classic DB structure of Orders has zero or more OrderLines and OrderLine

  • 0

Given a classic DB structure of Orders has zero or more OrderLines and OrderLine has exactly one Product, how do I write a LINQ query to express this?

The output would be

OrderNumber - OrderLine - Product Name
Order-1       null        null // (this order has no lines)
Order-2       1           Red widget

I tried this query but is not getting the orders with no lines

var model = (from po in Orders
             from line in po.OrderLines
                select new
                {
                    OrderNumber = po.Id,
                    OrderLine = line.LineNumber,
                    ProductName = line.Product.ProductDescription,
                }
             )
  • 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-14T23:10:53+00:00Added an answer on May 14, 2026 at 11:10 pm

    Here is an article which appears to explain how to achieve exactly what you are trying to do.

    public static void OuterJoinSimpleExample()
    {
        var customers = new List<Customer>() { 
            new Customer {Key = 1, Name = "Gottshall" },
            new Customer {Key = 2, Name = "Valdes" },
            new Customer {Key = 3, Name = "Gauwain" },
            new Customer {Key = 4, Name = "Deane" },
            new Customer {Key = 5, Name = "Zeeman" } 
        };
    
        var orders = new List<Order>() {
            new Order {Key = 1, OrderNumber = "Order 1" },
            new Order {Key = 1, OrderNumber = "Order 2" },
            new Order {Key = 4, OrderNumber = "Order 3" },
            new Order {Key = 4, OrderNumber = "Order 4" },
            new Order {Key = 5, OrderNumber = "Order 5" },
        };
    
        var q = from c in customers
                join o in orders on c.Key equals o.Key into outer
                from o in outer.DefaultIfEmpty()
                select new { 
                    Name = c.Name, 
                    OrderNumber = ((o == null) ? "(no orders)" : o.OrderNumber) 
                };
    
        foreach (var i in q) {
            Console.WriteLine("Customer: {0}  Order Number: {1}", 
                i.Name.PadRight(11, ' '), i.OrderNumber);
        }
    
        Console.ReadLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a table that represents a hierarchical tree structure and has three columns ID
One of those classic programming interview questions... You are given two marbles, and told
I have been given control of a web site in Classic ASP. What is
I'm implementing the session sharing structure from this link for an ASP classic site
Given: I have a website that includes both ASP.NET Web Forms and Classic ASP
I'm currently trying to run a classic ASP application which I've been given source
Problem: Given a matrix in which each row and each column is sorted, write
I have an Exel 2007 PivotTable using classic layout that has 2 row fields.
I have two websites OLD.com (classic ASP) and NEW.com (ASP.NET) - each site has
I think my problem is a classic one, but I can't get the right

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.