Пример #1
0
        internal virtual async Task <ObjectResult <TResultType> > ExecuteAsync <TResultType>(
            ObjectContext context,
            ObjectParameterCollection parameterValues,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            DbDataReader               storeReader    = (DbDataReader)null;
            BufferedDataReader         bufferedReader = (BufferedDataReader)null;
            ObjectResult <TResultType> objectResult;

            try
            {
                using (EntityCommand entityCommand = this.PrepareEntityCommand(context, parameterValues))
                    storeReader = await entityCommand.GetCommandDefinition().ExecuteStoreCommandsAsync(entityCommand, this.Streaming ? CommandBehavior.Default : CommandBehavior.SequentialAccess, cancellationToken).WithCurrentCulture <DbDataReader>();
                ShaperFactory <TResultType> shaperFactory = (ShaperFactory <TResultType>) this.ResultShaperFactory;
                Shaper <TResultType>        shaper;
                if (this.Streaming)
                {
                    shaper = shaperFactory.Create(storeReader, context, context.MetadataWorkspace, this.MergeOption, true, this.Streaming);
                }
                else
                {
                    StoreItemCollection storeItemCollection = (StoreItemCollection)context.MetadataWorkspace.GetItemCollection(DataSpace.SSpace);
                    DbProviderServices  providerServices    = DbConfiguration.DependencyResolver.GetService <DbProviderServices>((object)storeItemCollection.ProviderInvariantName);
                    bufferedReader = new BufferedDataReader(storeReader);
                    await bufferedReader.InitializeAsync(storeItemCollection.ProviderManifestToken, providerServices, shaperFactory.ColumnTypes, shaperFactory.NullableColumns, cancellationToken).WithCurrentCulture();

                    shaper = shaperFactory.Create((DbDataReader)bufferedReader, context, context.MetadataWorkspace, this.MergeOption, true, this.Streaming);
                }
                TypeUsage resultItemEdmType = this.ResultType.EdmType.BuiltInTypeKind != BuiltInTypeKind.CollectionType ? this.ResultType : ((CollectionType)this.ResultType.EdmType).TypeUsage;
                objectResult = new ObjectResult <TResultType>(shaper, this._singleEntitySet, resultItemEdmType);
            }
            catch (Exception ex)
            {
                if (this.Streaming && storeReader != null)
                {
                    storeReader.Dispose();
                }
                if (!this.Streaming && bufferedReader != null)
                {
                    bufferedReader.Dispose();
                }
                throw;
            }
            return(objectResult);
        }
Пример #2
0
        internal virtual ObjectResult <TResultType> Execute <TResultType>(
            ObjectContext context,
            ObjectParameterCollection parameterValues)
        {
            DbDataReader       reader             = (DbDataReader)null;
            BufferedDataReader bufferedDataReader = (BufferedDataReader)null;

            try
            {
                using (EntityCommand entityCommand = this.PrepareEntityCommand(context, parameterValues))
                    reader = entityCommand.GetCommandDefinition().ExecuteStoreCommands(entityCommand, this.Streaming ? CommandBehavior.Default : CommandBehavior.SequentialAccess);
                ShaperFactory <TResultType> resultShaperFactory = (ShaperFactory <TResultType>) this.ResultShaperFactory;
                Shaper <TResultType>        shaper;
                if (this.Streaming)
                {
                    shaper = resultShaperFactory.Create(reader, context, context.MetadataWorkspace, this.MergeOption, true, this.Streaming);
                }
                else
                {
                    StoreItemCollection itemCollection = (StoreItemCollection)context.MetadataWorkspace.GetItemCollection(DataSpace.SSpace);
                    DbProviderServices  service        = DbConfiguration.DependencyResolver.GetService <DbProviderServices>((object)itemCollection.ProviderInvariantName);
                    bufferedDataReader = new BufferedDataReader(reader);
                    bufferedDataReader.Initialize(itemCollection.ProviderManifestToken, service, resultShaperFactory.ColumnTypes, resultShaperFactory.NullableColumns);
                    shaper = resultShaperFactory.Create((DbDataReader)bufferedDataReader, context, context.MetadataWorkspace, this.MergeOption, true, this.Streaming);
                }
                TypeUsage resultItemType = this.ResultType.EdmType.BuiltInTypeKind != BuiltInTypeKind.CollectionType ? this.ResultType : ((CollectionType)this.ResultType.EdmType).TypeUsage;
                return(new ObjectResult <TResultType>(shaper, this._singleEntitySet, resultItemType));
            }
            catch (Exception ex)
            {
                if (this.Streaming && reader != null)
                {
                    reader.Dispose();
                }
                if (!this.Streaming && bufferedDataReader != null)
                {
                    bufferedDataReader.Dispose();
                }
                throw;
            }
        }