title: Join two tables using LINQ Query and order based two parameters
body: <p>I have two tables Customers and Orders. I want a LINQ query to fetch list of all the orders placed by all the customers organized first by month and then by year. If there is no order corresponding to the customer, "No Orders” should be displayed.</p>
  
  <p>The columns of Customers table are </p>
  
  <pre><code>customer_id
  name
  city
  </code></pre>
  
  <p>The columns of Orders table are</p>
  
  <pre><code>order_id
  order_date
  order_total
  customer_id
  </code></pre>
  
  <p>I tried writing it the following way but its not giving complete output. </p>
  
  <pre><code>var res = from cust in db.Customers 
            join ord in db.Orders 
                 on cust.customer_id equals ord.customer_id into g 
            from d in g.DefaultIfEmpty() 
            select new { 
                 name=cust.name, 
                 oId=d.order_id==null?-1:d.order_id 
            };   
  </code></pre>
  
  <p>How do I rectify it?</p>