Home > Asp.net MVC > Left outer join in LINQ

Left outer join in LINQ

we can implement left outer join in LINQ as well

suppose i have 2 tables 

1. product 

2. order. 

In the order we have foreign key named as productId reference to product table

Now we want to achieve left or left outer join

var q=(from pd in dataContext.Products

             join od in dataContext.Orders on pd.ProductID equals od.ProductID into t

            from rt in t.DefaultIfEmpty()

            select new { 

                                  pd.name,

                                  ….

               }).ToList();

 

Thanks 

🙂

 

This Article is TAGGED in . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">