Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Tuesday, 31 October 2017

INNER JOIN Example Using LINQ In C# Asp.Net

 asp.net, Asp.Net C#, csharp, guruji point, Gurujipoint, Inner Join using LINQ, LINQ, LINQ Examples, LINQ Practice     No comments   


Introduction
In this article we will learn how to use join using LINQ in C#. Join example with LINQ using LIST collection. 


Previous Updates
In previous articles we have learnt  Maintain state of dynamic added userConrol in asp.net using c#. Insert Only Numeric values in Asp Textbox using Regex. 

Description:
Here i am using the List collection to store the temporary/static data. In your case may be it will the database data. 
Below is My two class just like two tables Student and Department.
        class Emp
        {
            public int EmpID { get; set; }
            public string EmpName { get; set; }
        }
        class Dep
        {
            public int DepID { get; set; }
            public string Department { get; set; }
            public int EmpID { get; set; }
        }
Below i fill the dummy data into List , it just like your SQL table data and now i want to retrieve only those employee records who are common with Departments.
Arrange Distinct Elements Of A List In Ascending Order Using LINQ
static void Main(string[] args)
{
    List<Emp> liEmp = new List<Emp>();
    liEmp.Add(new Emp { EmpID = 1, EmpName = "JP" });
    liEmp.Add(new Emp { EmpID = 2, EmpName = "AB" });
    liEmp.Add(new Emp { EmpID = 3, EmpName = "CD" });
    liEmp.Add(new Emp { EmpID = 6, EmpName = "EF" });
    liEmp.Add(new Emp { EmpID = 8, EmpName = "EF" });

    List<Dep> lstDep = new List<Dep>();
    lstDep.Add(new Dep { DepID = 1, Department = ".Net", EmpID = 1 });
    lstDep.Add(new Dep { DepID = 2, Department = "PHP", EmpID = 2 });
    lstDep.Add(new Dep { DepID = 3, Department = "ASP", EmpID = 3 });
    lstDep.Add(new Dep { DepID = 4, Department = "Android", EmpID = 4 });
    lstDep.Add(new Dep { DepID = 5, Department = "GD", EmpID = 5 });
    lstDep.Add(new Dep { DepID = 6, Department = "UI", EmpID = 6 });

    //InnerJoin Using LINQ 
    var finalData = from emp in liEmp
                    join dep in lstDep
         on emp.EmpID equals dep.EmpID
                    select new
                    {
                        emp.EmpID,
                        emp.EmpName,
                        dep.Department
                    };
    foreach (var data in finalData)
    {
        Console.WriteLine("EmpId = " + data.EmpID
                         + ",Emp Name = " + data.EmpName +
                        ",Department = " + data.Department);
    }
    Console.ReadLine();
}
Output:
EmpId = 1,Emp Name = JP,Department = .Net
EmpId = 2,Emp Name = AB,Department = PHP
EmpId = 3,Emp Name = CD,Department = ASP
EmpId = 6,Emp Name = EF,Department = UI

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home

0 comments:

Post a comment

Facebook Updates

Guruji Point

Popular Posts

  • Base64 Encoding And Decoding In SQL Server
    Introduction In this article we will learn How to encode a string into Base64String and how to decode Base64String to string. How to crea...
  • Trigger In SQL Server - Insert Update Delete In Single Trigger With Example
    Introduction In this article we will learn what is trigger . How to manage Insert, Update and Delete operation in trigger. Insert Update ...
  • Convert DataSet To List Or GenericList Using LINQ - C#
    Introduction In this article we will learn how to convert dataset to list or convert DataSet to List of collection o generic list in c#. ...
  • Difference Between DataAdapter And DataReader In Asp.Net With Example
    Introduction In this article we will learn what is DataAdapter and DataReader. What is the difference between dataadapter and datareader....
  • Read List With In List Collection Using LINQ - Increase Application Data Performances
    Introduction In this article we will learn about how to read data from a SubList or list with in list collection. How to access sub list p...

Categories

comma seperated string in sql Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS row_number() and dense_rank() salary table structure. Scope_Identity() Use of indexes while loop in sql why do we need cursor why tuple used

Best Deal Here

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write