Ejemplo n.º 1
0
 public void EntitySplittingWithOfficeAssignment()
 {
     using (var context = new SchoolEntities())
     {
         foreach (var person in context.People.OfType <Professor>())
         {
             Console.WriteLine($"{person.FullName.FirstName} {person.FullName.LastName} ({person.Location})");
         }
     }
 }
Ejemplo n.º 2
0
        public void EntitySplittingWithOfficeAssignment()
        {
            using (var context = new SchoolEntities())
            {
                foreach (var person in context.People.OfType<Professor>())
                {
                    Console.WriteLine($"{person.FullName.FirstName} {person.FullName.LastName} ({person.Location})");
                }

            }
        }
Ejemplo n.º 3
0
        public void DemoVanQuery()
        {
            using (var context =new SchoolEntities())
            {
                var query = from p in context.People
                            where p.FullName.FirstName.StartsWith("Bob")
                            select p.FullName.LastName;

                Console.WriteLine(query);
            }
        }
Ejemplo n.º 4
0
        public void DemoVanQuery()
        {
            using (var context = new SchoolEntities())
            {
                var query = from p in context.People
                            where p.FullName.FirstName.StartsWith("Bob")
                            select p.FullName.LastName;

                Console.WriteLine(query);
            }
        }
Ejemplo n.º 5
0
        public void FindVsSingleOrDefault()
        {
            using (var context = new SchoolEntities())
            {
                context.Database.Log = Console.WriteLine;

                int id = 6;
                var li1 = (from p in context.People
                          where p.PersonID == id
                          select p).SingleOrDefault();

                var li2 = context.People.Find(7);
            }
        }
Ejemplo n.º 6
0
 public void StudentGradesOnStudent()
 {
     using (var context = new SchoolEntities())
     {
         foreach (var student in context.People.OfType <Student>())
         {
             Console.WriteLine($"{student.FullName.FirstName} {student.FullName.LastName}");
             foreach (var grade in student.Grades)
             {
                 Console.WriteLine($"  {grade.Course.Title}: {grade.Grade}");
             }
         }
     }
 }
Ejemplo n.º 7
0
        public void FindVsSingleOrDefault()
        {
            using (var context = new SchoolEntities())
            {
                context.Database.Log = Console.WriteLine;

                int id  = 6;
                var li1 = (from p in context.People
                           where p.PersonID == id
                           select p).SingleOrDefault();

                var li2 = context.People.Find(7);
            }
        }
Ejemplo n.º 8
0
        public void StudentGradesOnStudent()
        {
            using (var context = new SchoolEntities())
            {
                foreach (var student in context.People.OfType<Student>())
                {
                    Console.WriteLine($"{student.FullName.FirstName} {student.FullName.LastName}");
                    foreach (var grade in student.Grades)
                    {
                        Console.WriteLine($"  {grade.Course.Title}: {grade.Grade}");
                    }
                }

            }
        }
Ejemplo n.º 9
0
        public void TestMethod1()
        {
            using (var context = new SchoolEntities())
            {
                foreach (var course in context.Courses.OfType <OnsiteCourse>())
                {
                    Console.WriteLine($"{course.Title} {course.Location}");
                }

                foreach (var course in context.Courses.OfType <OnlineCourse>())
                {
                    Console.WriteLine($"{course.Title} {course.URL}");
                }
            }
        }
Ejemplo n.º 10
0
 public void PagingInEntityFramework()
 {
     using (var context = new SchoolEntities())
     {
         for (int i = 0; i < context.People.Count(); i += 5)
         {
             Console.WriteLine($"[[[[{i}]]]]");
             foreach (var p in context.People
                 .OrderBy(p => p.PersonID)
                 .Skip(() => i) // <---- query met constant zorgt voor constante query!
                 .Take(5))
             {
                 Console.WriteLine($"{p.FullName.FirstName} {p.FullName.LastName}");
             }
         }
     }
 }
Ejemplo n.º 11
0
        public void TablePerHierarchyOnPerson()
        {
            using (var context = new SchoolEntities())
            {
                Console.WriteLine("-- Professors: ");
                foreach (var person in context.People.OfType <Professor>())
                {
                    Console.WriteLine($"{person.FullName.FirstName} {person.FullName.LastName} ({person.HireDate})");
                }

                Console.WriteLine("-- Students: ");
                foreach (var person in context.People.OfType <Student>())
                {
                    Console.WriteLine($"{person.FullName.FirstName} {person.FullName.LastName} ({person.EnrollmentDate})");
                }
            }
        }
Ejemplo n.º 12
0
 public void PagingInEntityFramework()
 {
     using (var context = new SchoolEntities())
     {
         for (int i = 0; i < context.People.Count(); i += 5)
         {
             Console.WriteLine($"[[[[{i}]]]]");
             foreach (var p in context.People
                      .OrderBy(p => p.PersonID)
                      .Skip(() => i) // <---- query met constant zorgt voor constante query!
                      .Take(5))
             {
                 Console.WriteLine($"{p.FullName.FirstName} {p.FullName.LastName}");
             }
         }
     }
 }
Ejemplo n.º 13
0
        public void WatIsLazyLoading()
        {
            using (var context = new SchoolEntities())
            {
                //context
                //    .Configuration
                //    .LazyLoadingEnabled = false;

                foreach (var persoon in context
                         .People
                         .OfType <Student>()
                         .Include(s => s.Grades))
                {
                    foreach (var grades in persoon.Grades)
                    {
                        Console.WriteLine(grades.Grade);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public void TablePerHierarchyOnPerson()
        {
            using (var context = new SchoolEntities())
            {
                Console.WriteLine("-- Professors: ");
                foreach (var person in context.People.OfType<Professor>())
                {
                    Console.WriteLine($"{person.FullName.FirstName} {person.FullName.LastName} ({person.HireDate})");
                }

                Console.WriteLine("-- Students: ");
                foreach (var person in context.People.OfType<Student>())
                {
                    Console.WriteLine($"{person.FullName.FirstName} {person.FullName.LastName} ({person.EnrollmentDate})");
                }

            }
        }
Ejemplo n.º 15
0
        public void WatIsLazyLoading()
        {
            using (var context = new SchoolEntities())
            {
                //context
                //    .Configuration
                //    .LazyLoadingEnabled = false;

                foreach (var persoon in context
                    .People
                    .OfType<Student>()
                    .Include(s => s.Grades))
                {
                    foreach (var grades in persoon.Grades)
                    {
                        Console.WriteLine(grades.Grade);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public void TestMethod1()
        {
            using (var context = new SchoolEntities())
            {
                foreach (var course in context.Courses.OfType<OnsiteCourse>())
                {
                    Console.WriteLine($"{course.Title} {course.Location}");
                }

                foreach (var course in context.Courses.OfType<OnlineCourse>())
                {
                    Console.WriteLine($"{course.Title} {course.URL}");
                }

            }
        }