Suhaibnm
Suhaibnm

Reputation: 89

Linq to sql - left outer Join

I have Three Table without assosiatated as Follows

  1. Clients
  2. Bank
  3. Country

Some clients they don't Have bank Details so I need to get all the Cleint Info Who has the bank and Who hasn't the bank, and same as country info

I know It's "left outer join" method. how its in the Linq to sql

vb.net code Please

Upvotes: 4

Views: 2691

Answers (2)

Pranay Rana
Pranay Rana

Reputation: 176896

enter image description here

var query = 
    from order in dc.Orders
    from vendor 
    in dc.Vendors
         .Where(v => v.Id == order.VendorId)
         .DefaultIfEmpty()
    from status 
    in dc.Status
         .Where(s => s.Id == order.StatusId)
         .DefaultIfEmpty()
    select new { Order = order, Vendor = vendor, Status = status } 
    //Vendor and Status properties will be null if the left join is null

LEFT OUTER JOIN in LINQ To SQL

Upvotes: 4

GONeale
GONeale

Reputation: 26494

If you know your SQL query, create your left join and execute it through LinqPad.

It can then output the corresponding LINQ query.

Best of luck.

Upvotes: 1

Related Questions