TABLES JOIN CLAUSE in LINQ ENTITY

Unknown | 9:19 PM |

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

using System.IO;

namespace LinqSamples
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        TMSMASTEREntities1 SDC = new TMSMASTEREntities1();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TMSMASTERConnectionString"].ConnectionString.ToString());
                BindGrid();             

            }

        }
        private void BindGrid()
        {

            //var query = from d in SDC.Employees
            //            from l in SDC.Students.Where(loc => loc.StudentId == d.EmpID).DefaultIfEmpty()
            //            where d.Emp_Name.Contains("fg") || l.Name.Contains("fgh")
            //            select new
            //            {
            //                Employees = d,
            //                Students = l,
                          
            //            };

            //var results = (from r in query.AsEnumerable()
            //               select new
            //               {
            //                   Emp_Name = r.Employees.Emp_Name,
            //                   Emp_Address = r.Employees.Emp_Address,                              
            //                   StudentId = r.Students.StudentId,
            //                   Name = r.Students.Name,
            //                   Address = r.Students.Address,
            //                   BirthDate = r.Students.BirthDate,
            //                   Image = r.Students.Image,
            //                   Email = r.Students.Email,
            //                   Mobile = r.Students.Mobile,
            //                   Description = r.Students.Description
                             
            //               }).ToList();


            var results = (from d in SDC.Employees
                           join l in SDC.Students on d.EmpID equals l.StudentId                         
                           select new
                           {
                               Emp_Name =d.Emp_Name,
                               Emp_Address =d.Emp_Address,
                               StudentId = l.StudentId,
                               Name = l.Name,
                               Address = l.Address,
                               BirthDate = l.BirthDate,
                               Image = l.Image,
                               Email = l.Email,
                               Mobile = l.Mobile,
                               Description = l.Description
                           }).ToList();
           

            grid.DataSource = results;
            grid.DataBind();

        }

   }

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....