How to use Join with LINQ
using System;
using System.Linq;
using System.Configuration;
public partial class LINQWithJoin
: System.Web.UI.Page
{
    TestDataClassesDataContext objDBContext = new TestDataClassesDataContext(ConfigurationManager.ConnectionStrings["TestConnectionString"].ToString());
    protected void
Page_Load(object sender, EventArgs e)
    {
    }
    protected void
btnDisplay_Click(object sender, EventArgs e)
    {
        var Allcity = from
city in objDBContext.City_Tbls join state in
objDBContext.State_Tbls on city.State_Id equals state.State_Id 
                            select
new 
                            { 
                              
CityName=city.Name, 
                              
StateName=state.Name
                            };
       
GridView1.DataSource = Allcity;
       
GridView1.DataBind();
    }
}
int above code CityName & StateName works as a alias from city.Name and state.Name
such as in SqlQuery.
Comments
Post a Comment