Ejemplo n.º 1
0
        private static void ImportXMLToSqlServer()
        {
            Console.WriteLine("Importing Data from Xml to Sql Server...");
            var db = new FactoryDbContext();

            var collection = FactoryXmlImporter.ImportSpaceships(Constants.XmlDataToImport);

            foreach (var spaceship in collection)
            {
                var sp = new SpaceshipMission
                {
                    SpaceshipName       = spaceship.SpaceshipName,
                    Captain             = spaceship.Captain,
                    HomePlanet          = spaceship.HomePlanet,
                    NumberOfCrewMembers = spaceship.NumberOfCrewMembers,
                    MissionType         = spaceship.MissionType,
                    Commision           = spaceship.Commission,
                    MissionStatus       = spaceship.MissionStatus
                };

                db.SpaceshipMissions.Add(sp);

                db.SaveChanges();
                db = new FactoryDbContext();
            }

            db.SaveChanges();
        }
Ejemplo n.º 2
0
        private static void ImportXmlToMongoDb()
        {
            Console.WriteLine("Importing Data from Xml to MongoDB...");
            var mongo = new MongoClient(Constants.MongoDbConnectionString);
            var db    = mongo.GetDatabase(Constants.DataName);

            var collection = FactoryXmlImporter.ImportSpaceships(Constants.XmlDataToImport);

            var mongoCollection = db.GetCollection <SpaceshipMissionsXmlModel>("missions");

            foreach (var spaceship in collection)
            {
                mongoCollection.InsertOne(spaceship);
            }
        }