コード例 #1
0
        /// <summary>
        /// Create a new Teen object.
        /// </summary>
        /// <param name="memberId">Initial value of the MemberId property.</param>
        /// <param name="name">Initial value of the Name property.</param>
        /// <param name="phone">Initial value of the Phone property.</param>
        /// <param name="age">Initial value of the Age property.</param>
        public static Teen CreateTeen(global::System.Int32 memberId, global::System.String name, global::System.String phone, global::System.Int32 age)
        {
            Teen teen = new Teen();

            teen.MemberId = memberId;

            teen.Name = name;

            teen.Phone = phone;

            teen.Age = age;

            return(teen);
        }
コード例 #2
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                var teen = new Teen {
                    Name = "Steven Keller", Age = 17, Phone = "817 867-5309"
                };
                var adult = new Adult {
                    Name = "Margret Jones", Age = 53, Phone = "913 294-6059"
                };
                var senior = new Senior {
                    Name = "Roland Park", Age = 71, Phone = "816 353-4458"
                };
                context.Members.AddObject(teen);
                context.Members.AddObject(adult);
                context.Members.AddObject(senior);
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                Console.WriteLine("Club Members");
                Console.WriteLine("============");
                foreach (var member in context.Members)
                {
                    bool   printPhone = true;
                    string str        = string.Empty;
                    if (member is Teen)
                    {
                        str        = " a Teen";
                        printPhone = false;
                    }
                    else if (member is Adult)
                    {
                        str = "an Adult";
                    }
                    else if (member is Senior)
                    {
                        str = "a Senior";
                    }
                    Console.WriteLine("{0} is {1} member, phone: {2}", member.Name, str, printPhone ? member.Phone : "unavailable");
                }
            }

            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
        }