ASP.Net : LINQ and SQL to access record from two tables

LINQ to access  rows from two table  after join on common field

1 .create two table  emp  and dept


2. Add LINQ to SQL Classess



3. Add( drag and  drop) both tables on  DataClasses.dbml ( Designer)



4. LINQ Code for above

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

public partial class linqfromtwotables : System.Web.UI.Page
    DataClassesDataContext o = new DataClassesDataContext();

    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
       var query = from p in join d in o.students on p.cid equals d.rollno  select new { p.cname, d.sname };
       GridView1.DataSource = query;

5.  Output

ff46. Sample data from table emp and dept!