Linq to sql - left external join

I have three tables without associations, as follows

  • Customers
  • Bank
  • The country

Some customers do not have bank data, so I need to get all the customer information. Who has a bank and who does not have a bank, as well as information about the country.

I know this is the "left external join" method. like him in linq to sql

Vb.net code Please

+4
source share
2 answers

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

+4
source

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

Then it can output the corresponding LINQ query.

Good luck.

+1
source

All Articles