Thursday, 29 December 2011

Join with three tables using Linq Query

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class Default3 : System.Web.UI.Page
{
public string connection = ConfigurationManager.ConnectionStrings["DemoConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
DataClassesDataContext dc = new DataClassesDataContext(connection);
var x=from m in dc.mytables join y in dc.yourtables on m.pid equals y.pid into grouping from y in dc.yourtables join o in dc.ourtables on y.pid equals o.pid select new{m.name, y.pid,y.money,o.first,o.second };
GridView1.DataSource = x;
GridView1.DataBind();
}
}

No comments:

Post a Comment