コード例 #1
0
        public static DbCommand CreateBulkQueryCommand(
            DbConnection connection,
            string sqlStatement,
            IEnumerable parameters,
            bool paramsAsList,
            SourceAdapterBuilderDelegate sourceAdapterBuilder,
            TargetAdapterBuilderDelegate adapterBuilder)
        {
            ColumnMetadataList metadata = null;

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var param in parameters)
            {
                metadata = new ColumnMetadataList {
                    new ColumnMetadata
                    {
                        ColumnName = "P",
                        DataType   = param.GetType()
                    }
                };
                break;
            }
            if (metadata == null)
            {
                throw new InvalidOperationException("parameters enumerable is empty");
            }

            return(CreateBulkQueryCommand(connection, sqlStatement, metadata, parameters, paramsAsList, sourceAdapterBuilder, adapterBuilder));
        }
コード例 #2
0
        public static DbCommand CreateBulkQueryCommand(
            DbConnection connection,
            string sqlStatement,
            ColumnMetadataList metadata,
            IEnumerable parameters,
            bool paramsAsList,
            SourceAdapterBuilderDelegate sourceAdapterBuilder,
            TargetAdapterBuilderDelegate adapterBuilder)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }
            if (sourceAdapterBuilder == null)
            {
                throw new ArgumentNullException(nameof(sourceAdapterBuilder));
            }
            if (adapterBuilder == null)
            {
                throw new ArgumentNullException(nameof(adapterBuilder));
            }

            var sourceAdapter = sourceAdapterBuilder(parameters, metadata);
            var adapter       = adapterBuilder(sqlStatement, metadata, connection, paramsAsList);

            adapter.Prepare(sourceAdapter);
            try
            {
                foreach (var row in sourceAdapter.RowsEnumerable)
                {
                    adapter.Process(row);
                }
                adapter.BindParameters();
                return(adapter.TakeCommand());
            }
            finally
            {
                adapter.UnPrepare();
            }
        }