Beispiel #1
0
        static void Main(string[] args)
        {
            var JoinUsingMS = Employee1.GetAllEmployees() //Outer Data Source
                              .Join(
                Address.GetAllAddress(),                  //Inner Data Source
                employee => employee.AddressId,           //Inner Key Selector
                address => address.ID,                    //Outer Key selector
                (employee, address) => new                //Projecting the data into a result set
            {
                EmployeeName = employee.Name,
                AddressLine  = address.AddressLine
            }).ToList();

            Console.WriteLine("Name \t Address");
            foreach (var employee in JoinUsingMS)
            {
                Console.WriteLine(employee.EmployeeName + "\t" + employee.AddressLine);
            }
            Console.ReadLine();

            var JoinUsingQS = (from emp in Employee1.GetAllEmployees()
                               join address in Address.GetAllAddress()
                               on emp.AddressId equals address.ID
                               select new
            {
                EmployeeName = emp.Name,
                AddressLine = address.AddressLine
            }).ToList();

            foreach (var employee in JoinUsingQS)
            {
                Console.WriteLine($"Name :{employee.EmployeeName}, Address : {employee.AddressLine}");
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var MSOuterJOIN = Employee1.GetAllEmployees()
                              .GroupJoin(
                Address.GetAllAddress(),
                emp => emp.AddressId,
                add => add.ID,
                (emp, add) => new { emp, add }
                )
                              .SelectMany(
                x => x.add.DefaultIfEmpty(),
                (employee, address) => new { employee, address }
                );

            foreach (var item in MSOuterJOIN)
            {
                Console.WriteLine($"Name : {item.employee.emp.Name}, Address : {item.address?.AddressLine} ");
            }
            Console.ReadLine();
        }