In this blog you will find ASP.NET 3.5 articles and some code samples. These code samples are created by me and should be working. Thanks for visiting my blog! Happy Dot Netting

Thursday, January 22, 2009

LINQ to SQL - Inner Join

LINQ to SQL query to perform inner join on tables Product and ProductDocument on productID as primary key

protected void Page_Load(object sender, EventArgs e)
    {
        MydbDataContext db1 = new MydbDataContext();
        //LINQ to SQL query to perform inner join on tables Product and ProductDocument on productID as primary key
        var query = db1.Products.Join(db1.ProductDocuments, p => p.ProductID, m => m.ProductID, (c, m) => new {c.ProductID,m.DocumentID,c.Name });
        GridView1.DataSource = query;
        GridView1.DataBind();
    }



No comments: