private void MetadataCachingWithGarbageCollectionTemplate(Action garbageCollection) { MetadataWorkspace.ClearCache(); var weakReferences = new WeakReference[3]; // load metadata using (var connection1 = new EntityConnection(connectionString)) { connection1.Open(); weakReferences[0] = new WeakReference(connection1.GetMetadataWorkspace().GetItemCollection(DataSpace.CSpace)); weakReferences[1] = new WeakReference(connection1.GetMetadataWorkspace().GetItemCollection(DataSpace.SSpace)); weakReferences[2] = new WeakReference(connection1.GetMetadataWorkspace().GetItemCollection(DataSpace.CSSpace)); } // perform necessary garbage collection steps garbageCollection(); // verify that metadata was cached using (var connection2 = new EntityConnection(connectionString)) { connection2.Open(); Assert.Same(weakReferences[0].Target, connection2.GetMetadataWorkspace().GetItemCollection(DataSpace.CSpace)); Assert.Same(weakReferences[1].Target, connection2.GetMetadataWorkspace().GetItemCollection(DataSpace.SSpace)); Assert.Same(weakReferences[2].Target, connection2.GetMetadataWorkspace().GetItemCollection(DataSpace.CSSpace)); } }
public static void ClearEfCaches() { MetadataWorkspace.ClearCache(); InformationSchemaManager.ClearInformationSchemaTable(); EntityFrameworkManager.Cache = new StaticObjectCache(); QueryCacheManager.Cache = new StaticObjectCache(); MemoryCache.Default.Flush(); ClearEfInternalCaches(); }
public void ClearCache_clears_cached_assembly_information_for_views() { var cache = DbConfiguration.GetService <IViewAssemblyCache>(); cache.CheckAssembly(typeof(PregenContextEdmxViews).Assembly, followReferences: true); Assert.True(cache.Assemblies.Contains(typeof(PregenContextEdmxViews).Assembly)); MetadataWorkspace.ClearCache(); Assert.Equal(0, cache.Assemblies.Count()); }
public void DatabaseViewCacheContextTests_allow_seting_table_and_schema_name() { MetadataWorkspace.ClearCache(); // TODO: mock connection? using (var ctx = new FakeDatabaseViewCacheContext( new SqlConnection(TestUtils.TempDbConnectionString), "MyViews", "schema")) { VerifyModel(DumpEdmx(ctx), "MyViews", "schema"); } }