public void TestTimeTakenWithDifferentTracked(int numTracked)
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <Chapter14DbContext>();

            using var context = new Chapter14DbContext(options);
            context.Database.EnsureCreated();

            AddMyEntities(context, numTracked);

            //ATTEMPT
            using (new TimeThings(_output, $"{numTracked} tracked"))
            {
                context.Add(new MyEntity());
                context.SaveChanges();
            }
            using (new TimeThings(_output, $"{numTracked} tracked"))
            {
                context.Add(new MyEntity());
                context.SaveChanges();
            }
            using (new TimeThings(_output, $"{numTracked} tracked"))
            {
                context.Add(new MyEntity());
                context.SaveChanges();
            }
            using (new TimeThings(_output, $"{numTracked} tracked"))
            {
                context.Add(new MyEntity());
                context.SaveChanges();
            }

            context.ChangeTracker.DetectChanges();

            //VERIFY
        }
Beispiel #2
0
        public void TestOneSaveChanges()
        {
            //SETUP
            var options = this.CreateUniqueClassOptions <Chapter14DbContext>();

            using var context = new Chapter14DbContext(options);
            context.Database.EnsureClean();

            //ATTEMPT
            using (new TimeThings(_output, "One SaveChanges"))
            {
                for (int i = 0; i < 100; i++)
                {
                    context.Add(new MyEntity());
                }
                context.SaveChanges();
            }
            using (new TimeThings(_output, "One SaveChanges"))
            {
                for (int i = 0; i < 100; i++)
                {
                    context.Add(new MyEntity());
                }
                context.SaveChanges();
            }
            using (new TimeThings(_output, "One SaveChanges"))
            {
                for (int i = 0; i < 100; i++)
                {
                    context.Add(new MyEntity());
                }
                context.SaveChanges();
            }

            //VERIFY
        }
        private void AddHashSet(Chapter14DbContext context, int numRelations, bool showResults = true)
        {
            var count  = context.ChangeTracker.Entries <SubEntity2>().Count();
            var entity = new MyEntity();

            for (int i = 0; i < numRelations; i++)
            {
                entity.HashSets.Add(new SubEntity2());
            }
            using (new TimeThings(result =>
            {
                if (showResults)
                {
                    _output.WriteLine(result.ToString());
                }
            }, $"Add: HasSet. #tracked = {count}", numRelations))
            {
                context.Add(entity);
            }
        }