public void EntityDataLoader_CommandTreeBuilder() { var connString = "NorthwindObjectContext"; var asm = typeof(NorthwindObjectContext).Assembly; var workspace = MetadataWorkspaceHelper.GetMetadataWorkspace(connString, asm); var entitySet = workspace.GetItems(DataSpace.SSpace) .OfType <EntityContainer>() .First() .BaseEntitySets .OfType <EntitySet>() .First(); var tree = CommandTreeBuilder.CreateSelectAll(workspace, entitySet); var query = tree as DbQueryCommandTree; query.Should().NotBeNull(); var scan = query.Query as DbScanExpression; scan.Should().NotBeNull(); scan.Target.Should().Be(entitySet); }
/// <summary> /// Initializes a new instance of the <see cref="EntityTableDataLoader" /> class. /// </summary> /// <param name="connection"> The connection towards the database. </param> /// <param name="table"> The metadata of the table. </param> public EntityTableDataLoader(EntityConnection connection, TableDescription table) : base(table) { this.connection = connection; this.workspace = connection.GetMetadataWorkspace(); this.entitySet = MetadataWorkspaceHelper .GetEntityContainer(this.workspace) .GetEntitySetByName(table.Name, true); }
/// <summary> /// Initializes a new instance of the <see cref="EntityTableDataLoader" /> class. /// </summary> /// <param name="connection"> The connection towards the database. </param> /// <param name="table"> The metadata of the table. </param> public EntityTableDataLoader(EntityConnection connection, TableDescription table) : base(table) { this.connection = connection; this.workspace = connection.GetMetadataWorkspace(); this.entitySet = MetadataWorkspaceHelper .GetEntityContainer(this.workspace) .BaseEntitySets .OfType <EntitySet>() .FirstOrDefault(x => x.GetSchema() == table.Schema && x.GetTableName() == table.Name); }
public void MetadataWorkspaceHelperRewrite() { EntityConnectionStringBuilder nameResolver = new EntityConnectionStringBuilder(NorthwindObjectContext.DefaultConnectionString); string resolvedConnectionString = ConfigurationManager.ConnectionStrings[nameResolver.Name].ConnectionString; EntityConnectionStringBuilder connectionString = new EntityConnectionStringBuilder(resolvedConnectionString); MetadataWorkspace workspace = MetadataWorkspaceHelper.Rewrite( connectionString.Metadata, EffortProviderConfiguration.ProviderInvariantName, EffortProviderManifestTokens.Version1); }
/// <summary> /// Returns a metadata workspace that is rewritten in order to be compatible the /// Effort provider. /// </summary> /// <param name="entityConnectionString"> /// The entity connection string that references the original metadata. /// </param> /// <returns> /// The rewritten metadata. /// </returns> private static MetadataWorkspace GetEffortCompatibleMetadataWorkspace( ref string entityConnectionString) { EffortProviderConfiguration.VerifyProvider(); entityConnectionString = GetFullEntityConnectionString(entityConnectionString); EntityConnectionStringBuilder connectionStringBuilder = new EntityConnectionStringBuilder(entityConnectionString); return(MetadataWorkspaceStore.GetMetadataWorkspace( connectionStringBuilder.Metadata, metadata => MetadataWorkspaceHelper.Rewrite( metadata, EffortProviderConfiguration.ProviderInvariantName, EffortProviderManifestTokens.Version1))); }
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); }