Beispiel #1
0
 private static void CountSets()
 {
     Console.WriteLine("Counting sets...");
     using (var db = new LegoDbContext()) {
         Console.WriteLine(db.Sets.Count());
     }
 }
Beispiel #2
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();
            }
        }
Beispiel #3
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");
        }
Beispiel #4
0
        private static void DumpDatabase()
        {
            Console.WriteLine("Dumping Database...");
            const string tableFormat = "{0,-7} | {1 ,-16}";

            using (var context = new LegoDbContext()) {
                context.Database.Log = Console.WriteLine;
                Console.WriteLine(tableFormat, "Code", "Theme", "Description");
                var timer = Stopwatch.StartNew();
                var sets  = context.Sets
                            .Include(x => x.Theme1)
                            .Where(x => x.Theme1.Description == "Ninjago")
                            .Select(x => new { x.Code, x.Description })
                            .ToList();
                timer.Stop();
                Console.WriteLine($"Found {sets.Count} in {timer.ElapsedMilliseconds} ms");

                foreach (var set in sets.Take(10))
                {
                    Console.WriteLine(tableFormat, set.Code, set.Description);
                }
            }
        }