Beispiel #1
0
 static void CleanupDB()
 {
     using (var context = new DMContext())
     {
         context.Database.ExecuteSqlCommand("delete from Factors");
         context.Database.ExecuteSqlCommand("delete from Categories");
         context.SaveChanges();
     }
 }
Beispiel #2
0
        static void QueryDB()
        {
            var stopWatch = new Stopwatch();
            List<Factor> factors;

            using (var context = new DMContext())
            {
                stopWatch.Start();
                var fieldId = context.Factors.First().Category.Fields.First(f => f.Name == "Val1").Id;
                factors = context.Factors
                    .Include("Category")
                    .ToList() // Because of xml deserialization we cant do Linq to entity
                    .Where(f => f.Fields.Any(field => field.Id == fieldId && (field as FieldValue<int>).Value < 10))
                    .ToList();
                stopWatch.Stop();
            }

            var numberOfFactors = factors.Count;
            Console.WriteLine("Linq query of {0} factors took {1} ms", numberOfFactors, stopWatch.ElapsedMilliseconds);
            //factors.ForEach(PrintFactor);
        }
Beispiel #3
0
        static void WriteToDB(int numberOfFactors)
        {
            var stopWatch = new Stopwatch();
            var category = CreateCategory();
            var factors = new List<Factor>(numberOfFactors);
            for (int iterator = 1; iterator < numberOfFactors; iterator++)
            {
                factors.Add(CreateFactor(category, iterator));
            }

            using (var context = new DMContext())
            {
                stopWatch.Start();
                context.Categories.Add(category);
                context.Factors.AddRange(factors);
                context.SaveChanges();
                stopWatch.Stop();
            }

            Console.WriteLine("Writing of {0} factors to DB took {1} ms", numberOfFactors, stopWatch.ElapsedMilliseconds);
        }
Beispiel #4
0
        static void ReadFromDB()
        {
            var stopWatch = new Stopwatch();
            List<Factor> factors;
            ICollection<FieldValue> fields;

            using (var context = new DMContext())
            {
                stopWatch.Start();
                factors = context.Factors.Include("Category").ToList();
                foreach (var factor in factors)
                {
                    fields = factor.Fields;
                }
                stopWatch.Stop();
            }

            var numberOfFactors = factors.Count;
            Console.WriteLine("Reading of {0} factors from DB took {1} ms", numberOfFactors, stopWatch.ElapsedMilliseconds);
            //factors.Take(10).ToList().ForEach(PrintFactor);
        }