Esempio n. 1
0
        // Query a list of people, print out the properties of Person,
        // Student and BusinessStudent
        public static void Query()
        {
            using (EFTPHEntities context = new EFTPHEntities())
            {
                var people = from p in context.People
                             select p;

                foreach (var p in people)
                {
                    Console.WriteLine("Student {0} {1}",
                                      p.LastName,
                                      p.FirstName);

                    if (p is Student)
                    {
                        Console.WriteLine("EnrollmentDate: {0}",
                                          ((Student)p).EnrollmentDate);
                    }
                    if (p is BusinessStudent)
                    {
                        Console.WriteLine("BusinessCredits: {0}",
                                          ((BusinessStudent)p).BusinessCredits);
                    }
                }
            }
        }
Esempio n. 2
0
        // 查询people类型的列表, 输出Person, Student和BusinessStudent的属性
        public static void Query()
        {
            using (EFTPHEntities context = new EFTPHEntities())
            {
                var people = from p in context.People
                             select p;

                foreach (var p in people)
                {
                    Console.WriteLine("Student {0} {1}",
                        p.LastName,
                        p.FirstName);

                    if (p is Student)
                    {
                        Console.WriteLine("EnrollmentDate: {0}",
                            ((Student)p).EnrollmentDate);
                    }
                    if (p is BusinessStudent)
                    {
                        Console.WriteLine("BusinessCredits: {0}",
                            ((BusinessStudent)p).BusinessCredits);
                    }
                }

            }
        }