コード例 #1
0
 private static void DemonstrateTablePerType()
 {
     using (var context = new TablePerTypeDbContext())
     {
         AddVehiclesTablePerType(context);
         var allVehicles = context.Vehicles.ToList();
         var allCars     = context.Vehicles.OfType <Car>().ToList();
         var firstCar    = context.Vehicles.Find(allCars.First().Id);
     }
 }
コード例 #2
0
        private static void AddVehiclesTablePerType(TablePerTypeDbContext context)
        {
            context.Vehicles.Add(new Car
            {
                Fuel           = Fuel.Petrol,
                NumberOfWheels = 4,
                NumberOdSeats  = 5,
                DrivingPlates  = "EEP3587"
            });
            context.Vehicles.Add(new Car
            {
                Fuel           = Fuel.Petroleum,
                NumberOfWheels = 4,
                NumberOdSeats  = 2,
                DrivingPlates  = "EEH4685"
            });

            context.Vehicles.Add(new Truck
            {
                Fuel           = Fuel.Petroleum,
                NumberOfWheels = 6,
                EngineSize     = 4500,
                Cargo          = 7500
            });

            context.Vehicles.Add(new Truck
            {
                Fuel           = Fuel.Petroleum,
                NumberOfWheels = 10,
                EngineSize     = 6500,
                Cargo          = 12500
            });

            context.Vehicles.Add(new Motorbike
            {
                Fuel            = Fuel.Petrol,
                NumberOfWheels  = 2,
                NumberOfPistons = 1
            });
            context.SaveChanges();
        }