示例#1
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                context.ExecuteStoreCommand(@"insert into chapter6.toy 
                            (Name,ForDonationOnly) values ('RagDoll',1)");
                var toy = new Toy {
                    Name = "Fuzzy Bear", Price = 9.97M
                };
                var refurb = new RefurbishedToy {
                    Name = "Derby Car", Price = 19.99M, Quality = "Ok to sell"
                };
                context.Toys.AddObject(toy);
                context.Toys.AddObject(refurb);
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                Console.WriteLine("All Toys");
                Console.WriteLine("========");
                foreach (var toy in context.Toys)
                {
                    Console.WriteLine("{0}", toy.Name);
                }
                Console.WriteLine("\nRefurbished Toys");
                foreach (var toy in context.Toys.OfType <RefurbishedToy>())
                {
                    Console.WriteLine("{0}, Price = {1}, Quality = {2}", toy.Name, toy.Price, ((RefurbishedToy)toy).Quality);
                }
            }

            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
        }
示例#2
0
        /// <summary>
        /// Create a new RefurbishedToy object.
        /// </summary>
        /// <param name="toyId">Initial value of the ToyId property.</param>
        /// <param name="name">Initial value of the Name property.</param>
        /// <param name="quality">Initial value of the Quality property.</param>
        public static RefurbishedToy CreateRefurbishedToy(global::System.Int32 toyId, global::System.String name, global::System.String quality)
        {
            RefurbishedToy refurbishedToy = new RefurbishedToy();

            refurbishedToy.ToyId = toyId;

            refurbishedToy.Name = name;

            refurbishedToy.Quality = quality;

            return(refurbishedToy);
        }