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> /// Creates a data reader that retrieves the initial data from the database. /// </summary> /// <returns> /// The data reader. /// </returns> protected override IDataReader CreateDataReader() { // Build a command tree, which queries all records DbCommandTree commandTree = CommandTreeBuilder.CreateSelectAll(this.workspace, this.entitySet); // Get the provider services of the wrapped connection DbProviderServices providerServices = DbProviderServices.GetProviderServices(this.connection.StoreConnection); // Get current manifest token string manifestToken = providerServices.GetProviderManifestToken(this.connection.StoreConnection); // Get provider manifest DbProviderManifest providerManifest = providerServices.GetProviderManifest(manifestToken); // Create a command definition from the command tree DbCommandDefinition commandDefinition = providerServices.CreateCommandDefinition(providerManifest, commandTree); // Compile command DbCommand command = commandDefinition.CreateCommand(); // Setup command command.Connection = this.connection.StoreConnection; // Execute DbDataReader reader = command.ExecuteReader(); return(reader); }