Esempio n. 1
0
        private static void LazyLoading()
        {
            using (var ctx = new WorkshopContext())
            {
                var student = ctx.Students.FirstOrDefault();

                Console.WriteLine("Student Name " + student.Name);
                Console.WriteLine("Class Name " + student.StudentClass.Name);
            }
        }
Esempio n. 2
0
        private static void EagerLoading()
        {
            using (var ctx = new WorkshopContext())
            {
                var student = ctx.Students
                              .Where(s => s.Name.Equals("Vanita"))
                              .Include(a => a.StudentClass)
                              .FirstOrDefault();

                Console.WriteLine("Student Name " + student.Name);
                Console.WriteLine("Class Name " + student.StudentClass.Name);
            }
        }
Esempio n. 3
0
        private static void ExplicitLoading()
        {
            using (var ctx = new WorkshopContext())
            {
                var student = ctx.Students
                              .Where(s => s.Name.Equals("Vanita"))
                              .Select(s => new
                {
                    StudentName = s.Name,
                    ClassName   = s.StudentClass.Name
                })
                              .FirstOrDefault();

                Console.WriteLine("Student Name " + student.StudentName);
                Console.WriteLine("Class Name " + student.ClassName);
            }
        }