コード例 #1
0
ファイル: E2ETest.cs プロジェクト: ahmelsayed/efcache
        public void CUD_mapped_to_sprocs_reset_cache()
        {
            const string cachedItemKey =
                "EFCache.MyContext_SELECT TOP (1) \r\n    [c].[Id] AS [Id], \r\n    [c].[Data] AS [Data]\r\n    FROM [dbo].[EntitiesMappedToSprocs] AS [c]_";

            using (var ctx = new MyContext())
            {
                ctx.Database.ExecuteSqlCommand("INSERT INTO EntitiesMappedToSprocs VALUES(42)");
                var entity = ctx.EntitiesMappedToSprocs.FirstOrDefault();
                ctx.Entry(entity).State = EntityState.Modified;

                Assert.True(Cache.CacheDictionary.ContainsKey(cachedItemKey));

                ctx.SaveChanges();

                Assert.False(Cache.CacheDictionary.ContainsKey(cachedItemKey));
            }
        }
コード例 #2
0
ファイル: E2ETest.cs プロジェクト: ahmelsayed/efcache
        public void Cache_not_cleared_on_transaction_rollback()
        {
            Cache.PutItem("s", new object(), new[] { "Item", "Entity" }, new TimeSpan(), new DateTime());

            using (var ctx = new MyContext())
            {
                using(var entityConnection = ((IObjectContextAdapter)ctx).ObjectContext.Connection)
                {
                    entityConnection.Open();
                    var trx = entityConnection.BeginTransaction();

                    ctx.Entities.Add(new Entity());
                    ctx.Items.Add(new Item { Id = Guid.NewGuid() });

                    ctx.SaveChanges();

                    Assert.True(Cache.CacheDictionary.ContainsKey("s"));

                    trx.Rollback();

                    Assert.True(Cache.CacheDictionary.ContainsKey("s"));
                }
            }
        }
コード例 #3
0
ファイル: E2ETest.cs プロジェクト: ahmelsayed/efcache
 public void Can_read_null_values()
 {
     using (var trx = new TransactionScope())
     {
         using (var ctx = new MyContext())
         {
             ctx.Entities.Add(new Entity());
             ctx.SaveChanges();
             var e = ctx.Entities.First();
             Assert.Null(e.Name);
             Assert.Null(e.Flag);
         }
     }
 }
コード例 #4
0
ファイル: E2ETest.cs プロジェクト: ahmelsayed/efcache
        public void Cache_cleared_on_implicit_transaction_commit()
        {
            Cache.PutItem("s", new object(), new[] {"Item", "Entity"}, new TimeSpan(), new DateTime());

            using (var ctx = new MyContext())
            {
                ctx.Entities.Add(new Entity());
                ctx.Items.Add(new Item { Id = Guid.NewGuid()});

                ctx.SaveChanges();

                Assert.False(Cache.CacheDictionary.ContainsKey("s"));
            }
        }