コード例 #1
0
        private static void RecreateDatabase()
        {
            Console.WriteLine("Recreating database...");
            using (var context = new LegoDbContext()) {
                context.Database.Delete();
                context.Database.Create();

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

                context.SaveChanges();
            }
        }
コード例 #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");
        }