Example #1
0
        private static void RecreateDatabase()
        {
            Console.WriteLine("Recreating database...");
            using (var context = new LegoDbContext()) {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                ReadFromFile("./sets.csv", context);

                context.SaveChanges();
            }
        }
Example #2
0
        private static void ReadFromFile(string filename, LegoDbContext context)
        {
            var lines  = File.ReadAllLines(filename).Skip(1);
            var themes = context.Themes.ToList();

            var timer = Stopwatch.StartNew();

            foreach (var line in lines)
            {
                var set = ParseLegoSet(line, themes);
                context.Sets.Add(set);
            }
            context.SaveChanges();
            timer.Stop();
            Console.WriteLine($"Adding all sets took {timer.ElapsedMilliseconds} ms");
        }