Example #1
0
        public void GetDataWithNoTrackingIsDetached_notCache_notUpdate()
        {
            var id      = String.Empty;
            var newGuid = String.Empty;

            using (var context = new BlocksEntities())
            {
                var testEntity = context.TestEntity.AsNoTracking().FirstOrDefault();
                newGuid = Guid.NewGuid().ToString();
                testEntity.TESTENTITY2ID = newGuid;
                var EntityEntry = context.Entry(testEntity);
                Assert.Equal(EntityEntry.State, EntityState.Detached);

                id = testEntity.Id;
                context.SaveChanges();
                var newEntityNoTracking = context.TestEntity.AsNoTracking().FirstOrDefault(t => t.Id == id);
                Assert.NotEqual(newEntityNoTracking.TESTENTITY2ID, newGuid);

                var newEntity = context.TestEntity.FirstOrDefault(t => t.Id == id);
                Assert.NotEqual(newEntity.TESTENTITY2ID, newGuid);
            }

            using (var context = new BlocksEntities())
            {
                var testEntity = context.TestEntity.AsNoTracking().FirstOrDefault(t => t.Id == id);

                Assert.NotEqual(testEntity.TESTENTITY2ID, newGuid);
            }
        }