Exemplo n.º 1
0
        static void Main()
        {
            using (var model = new TelerikAcademyEntities())
            {
                // the bad way.
                //var employees = model.Employees.ToList().
                //                Join(model.Addresses, e => e.AddressID, a => a.AddressID, (e, a) => new { e, a }).ToList().
                //                Join(model.Towns, ad => ad.a.TownID, t => t.TownID, (ad, t) => new { ad, t }).ToList().
                //                Where(a => a.t.Name == "Sofia");

                //foreach (var employee in employees)
                //{
                //    Console.WriteLine(employee.ad.e.FirstName);
                //}

                // the good way
                var employees = from e in model.Employees
                                join a in model.Addresses on e.AddressID equals a.AddressID
                                join t in model.Towns on a.TownID equals t.TownID
                                where t.Name == "Sofia"
                                select e;

                foreach (var employee in employees)
                {
                    Console.WriteLine(employee.FirstName);
                }
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            using (var model = new TelerikAcademyEntities())
            {
                //with include.
                foreach (var employee in model.Employees.Include("Department").Include("Address"))
                {
                    Console.WriteLine("{0} {1} {2} {3}", 
                        employee.FirstName, employee.LastName, employee.Department.Name, employee.Address.AddressText);
                }

                //without include
                foreach (var employee in model.Employees)
                {
                    Console.WriteLine("{0} {1} {2} {3}",
                        employee.FirstName, employee.LastName, employee.Department.Name, employee.Address.AddressText);
                }
            }
        }