Ejemplo n.º 1
0
        static void AddCarProductCarFeature(CarsDBContext context, DefaultDeserializer deserializer)
        {
            var carProductsQuery = context.CarProducts;
            var carFeaturesQuery = context.CarFeatures;

            foreach (var car in deserializer.Find("Car"))
            {
                int carID = carProductsQuery.Where(s => s.Vin == car.Attributes["VIN"]).First().Id;
                foreach (var feature in car.FindChildren("Feature"))
                {
                    int featureID = carFeaturesQuery.Where(s => s.Code == feature.Attributes["Code"]).First().Id;
                    context.Add(new CarProductCarFeature {
                        CarProductId = carID, InstalledFeatureId = featureID
                    });
                }
            }
        }
Ejemplo n.º 2
0
        static void AddCarProducts(CarsDBContext context, DefaultDeserializer deserializer)
        {
            var carModelsQuery    = context.CarModels;
            var carFactoriesQuery = context.CarFactories;

            foreach (var factory in deserializer.Find("Factory"))
            {
                //finds factory id by correlating same factory name attribute and Name column in CarFactories
                int factoryID = carFactoriesQuery.Where(s => s.Name == factory.Attributes["Name"]).First().Id;
                foreach (var car in factory.FindChildren("Car"))
                {
                    int    carID   = carModelsQuery.Where(s => s.Name == car.FindChildren("Model").First().Value).First().Id;
                    short  carYear = short.Parse(car.FindChildren("ProductionYear").First().Value);
                    string carVIN  = car.Attributes["VIN"];
                    context.Add(new CarProducts {
                        CarModelId = carID, Year = carYear, Vin = carVIN, FactoryId = factoryID
                    });
                }
            }
        }