LINQ TO SQL Grouping
By AzamSharp
Views: 574

In this video Mohammad Azam will demonstrate how to use Grouping using LINQ to SQL classes.

static void Main(string[] args)
        {
            NorthwindDataContext northwind = new NorthwindDataContext();

            var list = from c in northwind.Categories
                       join p in northwind.Products
                       on c.id equals p.CategoryID
                       group p by c.CategoryName into products
                       select new
                       {
                           CategoryName = products.Key,
                           Products = products
                       };

            foreach (var item in list)
            {
                Console.WriteLine(item.CategoryName);

                foreach (var product in item.Products)
                {
                    Console.WriteLine(product.ProductName);
                }

                Console.WriteLine("------------------");
            }


        }

[Play the video]

By AzamSharp


Enter Comment/Feedback
  •  
  •  
  •  
  •  
  •  

Comments/Feedbacks



Join WebHost4Life.com






Copyright GridViewGuy 2007-2008