If you find this article useful, consider making a small donation to show your support for this web site and its content.
DiscountASP
AboutMe
About me:
Hi. My name is Farooq Kaiser and I'm a software developer from Toronto, Canada.

Implementing a Cross Join with LINQ

by Farooq Kaiser 13. February 2009 01:59

A cross join or Cartesian join is the basis for every other join.
The following query will produce all of the combinations of two tables using LINQ

var query = from c in customers              
   from p in products             
   select new            
   {               c.CompanyName,               
     p.ProductName           
   };


Querying DataSet, you can write the following Query with dataset.


var query = from c in ds.Tables["Table1"].AsEnumerable()              
     from p in ds.Tables["Table2"].AsEnumerable()               
     select new              
     {               Id = c["Id"],                  
       Name = p["Name"]              
     }; 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | C#

Comments

Jobs Autos Real estate Videos Power by Google