private static EntityConnection CreateInspectedFakeEntityConnection(string entityConnectionString, IResultSetComposer resultSetComposer, bool createFake, IDataLoader dataLoader) { EntityConnectionStringBuilder connectionString = new EntityConnectionStringBuilder(entityConnectionString); if (!string.IsNullOrEmpty(connectionString.Name)) { string resolvedConnectionString = ConfigurationManager.ConnectionStrings[connectionString.Name].ConnectionString; connectionString = new EntityConnectionStringBuilder(resolvedConnectionString); } List <XElement> csdl = new List <XElement>(); List <XElement> ssdl = new List <XElement>(); List <XElement> msl = new List <XElement>(); MetadataWorkspaceHelper.ParseMetadata(connectionString.Metadata, csdl, ssdl, msl); foreach (XElement ssdlFile in ssdl) { XAttribute providerAttribute = ssdlFile.Attribute("Provider"); XAttribute providerManifestTokenAttribute = ssdlFile.Attribute("ProviderManifestToken"); if (createFake) { EffortProviderConfiguration.VerifyProvider(); UniversalStorageSchemaModifier.Instance.Modify(ssdlFile, new EffortProviderInformation()); } string oldProviderInvariantName = providerAttribute.Value; string oldProviderManifestToken = providerManifestTokenAttribute.Value; providerAttribute.Value = DataReaderInspectorProviderConfiguration.ProviderInvariantName; providerManifestTokenAttribute.Value = string.Format("{0};{1}", oldProviderInvariantName, oldProviderManifestToken); } MetadataWorkspace convertedWorkspace = MetadataWorkspaceHelper.CreateMetadataWorkspace(csdl, ssdl, msl); DbConnection storeConnection = null; if (createFake) { storeConnection = Effort.DbConnectionFactory.CreateTransient(dataLoader); } else { storeConnection = ProviderHelper.CreateConnection(connectionString.Provider); storeConnection.ConnectionString = connectionString.ProviderConnectionString; } DbConnectionWrapper inspectorConnection = new DataReaderInspectorConnection(resultSetComposer); inspectorConnection.WrappedConnection = storeConnection; #if !EFOLD EntityConnection entityConnection = new EntityConnection(convertedWorkspace, inspectorConnection, true); #else EntityConnection entityConnection = new EntityConnection(convertedWorkspace, inspectorConnection); FieldInfo owned = typeof(EntityConnection) .GetField( "_userOwnsStoreConnection", BindingFlags.Instance | BindingFlags.NonPublic); owned.SetValue(entityConnection, false); #endif if (createFake) { using (ObjectContext objectContext = new ObjectContext(entityConnection)) { if (!objectContext.DatabaseExists()) { objectContext.CreateDatabase(); } } } return(entityConnection); }