static void Initialize() { using (var context = new CompanyDbContext()) { if (context.Cameras.Count() == 0) { context.Cameras.Add(new Camera() { Id = 1, Caption = "PowerShot G1 X Mark II", Manufacturer = "Canon", TypeNumber = "PowerShot G1 X Mark II", Lens = "12.5mm (W) - 62.5mm (T)" }); context.SaveChanges(); } if (context.SingleReflexCameras.Count() == 0) { context.SingleReflexCameras.Add(new SingleReflexCamera() { Id = 2, Caption = "EOS-1D X", Manufacturer = "Canon", TypeNumber = "EOS-1D X", LensMount = "Canon EF mount" }); context.SaveChanges(); } if (context.Lenses.Count() == 0) { context.Lenses.Add(new Lens() { Id = 3, Caption = "EF 16-35mm f/2.8L II USM", Manufacturer = "Canon", TypeNumber = "EF 16-35mm f/2.8L II USM", FocalLength = "16-35mm", MaxAperture = "F2.8" }); context.SaveChanges(); } } }
static void Main(string[] args) { Initialize(); using (var context = new CompanyDbContext()) { context.Cameras.Count(); Console.WriteLine("Camera Caption = {0}", context.Cameras.OfType <Product>().First().Caption); Console.WriteLine("SingleReflexCamera Caption = {0}", context.SingleReflexCameras.OfType <Product>().First().Caption); Console.WriteLine("Lens Caption = {0}", context.Lenses.OfType <Product>().First().Caption); } Console.Read(); }
static void Main(string[] args) { Initialize(); using (var context = new CompanyDbContext()) { context.Cameras.Count(); Console.WriteLine("Camera Caption = {0}", context.Cameras.OfType<Product>().First().Caption); Console.WriteLine("SingleReflexCamera Caption = {0}", context.SingleReflexCameras.OfType<Product>().First().Caption); Console.WriteLine("Lens Caption = {0}", context.Lenses.OfType<Product>().First().Caption); } Console.Read(); }