Exemplo n.º 1
0
 public static void Scenariu4()
 {
     using (var context = new Scenariu4())
     {
         var business = new Business
         {
             Name          = "Corner Dry Cleaning",
             LicenseNumber = "100x1"
         };
         context.Businesses.Add(business);
         var retail = new Retail
         {
             Name          = "Shop and Save",
             LicenseNumber =
                 "200C",
             Address = "101 Main",
             City    = "Anytown",
             State   = "TX",
             ZIPCode = "76106"
         };
         context.Businesses.Add(retail);
         var web = new eCommerce
         {
             Name          = "BuyNow.com",
             LicenseNumber =
                 "300AB",
             URL = "www.buynow.com"
         };
         context.Businesses.Add(web);
         context.SaveChanges();
     }
     using (var context = new Scenariu4())
     {
         Console.WriteLine("\n--- All Businesses ---");
         foreach (var b in context.Businesses)
         {
             Console.WriteLine("{0} (#{1})", b.Name, b.LicenseNumber);
         }
         Console.WriteLine("\n--- Retail Businesses ---");
         foreach (var r in context.Businesses.OfType <Retail>())
         {
             Console.WriteLine("{0} (#{1})", r.Name, r.LicenseNumber);
             Console.WriteLine("{0}", r.Address);
             Console.WriteLine("{0}, {1} {2}", r.City, r.State, r.ZIPCode);
         }
         Console.WriteLine("\n--- eCommerce Businesses ---");
         foreach (var e in context.Businesses.OfType <eCommerce>())
         {
             Console.WriteLine("{0} (#{1})", e.Name, e.LicenseNumber);
             Console.WriteLine("Online address is: {0}", e.URL);
         }
     }
 }
Exemplo n.º 2
0
 public void Add()
 {
     using (var context = new BusinessContext())
     {
         var business = new Business {
             Name = "Corner Dry Cleaning", LicenseNumber = "100x1"
         };
         context.Businesses.Add(business);
         var retail = new Retail
         {
             Name  = "Shop and Save", LicenseNumber = "200C", Address = "101 Main", City = "Anytown",
             State = "TX", ZIPCode = "76106"
         };
         context.Businesses.Add(retail);
         var web = new eCommerce {
             Name = "BuyNow.com", LicenseNumber = "300AB", URL = "www.buynow.com"
         };
         context.Businesses.Add(web);
         context.SaveChanges();
     }
 }