/// <summary>
        /// Creates a <see cref="DataMergeDefinition" /> from the specified <paramref name="importContext" />.
        /// </summary>
        /// <param name="importContext">The import context.</param>
        /// <returns>
        /// An instance of <see cref="DataMergeDefinition" />
        /// </returns>
        /// <exception cref="InvalidOperationException">Could not find matching field definition for data column</exception>
        protected virtual DataMergeDefinition CreateMergeDefinition(ImportProcessContext importContext)
        {
            var importDefinition = importContext.Definition;

            var mergeDefinition = new DataMergeDefinition();

            mergeDefinition.TargetTable   = importDefinition.TargetTable;
            mergeDefinition.IncludeInsert = importDefinition.CanInsert;
            mergeDefinition.IncludeUpdate = importDefinition.CanUpdate;

            // fluent builder
            var mergeMapping = new DataMergeMapping(mergeDefinition);

            // map included columns
            foreach (var fieldMapping in importContext.MappedFields)
            {
                var fieldDefinition = fieldMapping.Definition;
                var nativeType      = SqlTypeMapping.NativeType(fieldDefinition.DataType);

                mergeMapping
                .Column(fieldDefinition.Name)
                .Insert(fieldDefinition.CanInsert)
                .Update(fieldDefinition.CanUpdate)
                .Key(fieldDefinition.IsKey)
                .NativeType(nativeType);
            }

            return(mergeDefinition);
        }
Exemple #2
0
        private DataMergeDefinition CreateDefinition(BatchJob batchJob)
        {
            var mergeDefinition = new DataMergeDefinition();

            mergeDefinition.TargetTable   = batchJob.TargetTable;
            mergeDefinition.IncludeInsert = batchJob.CanInsert;
            mergeDefinition.IncludeUpdate = batchJob.CanUpdate;

            // fluent builder
            var mergeMapping = new DataMergeMapping(mergeDefinition);

            // map included columns
            foreach (var fieldMapping in batchJob.Fields.Where(m => m.Index.HasValue || m.Default.HasValue))
            {
                mergeMapping
                .Column(fieldMapping.Name)
                .Insert(fieldMapping.CanInsert)
                .Update(fieldMapping.CanUpdate)
                .NativeType(fieldMapping.NativeType)
                .Key(fieldMapping.IsKey);
            }

            return(mergeDefinition);
        }
        private DataMergeDefinition CreateDefinition(BatchJob batchJob)
        {
            var mergeDefinition = new DataMergeDefinition();
            mergeDefinition.TargetTable = batchJob.TargetTable;
            mergeDefinition.IncludeInsert = batchJob.CanInsert;
            mergeDefinition.IncludeUpdate = batchJob.CanUpdate;

            // fluent builder
            var mergeMapping = new DataMergeMapping(mergeDefinition);

            // map included columns
            foreach (var fieldMapping in batchJob.SourceMapping.Where(c => c.IsIncluded))
            {
                mergeMapping
                    .Column(fieldMapping.Name)
                    .Insert(fieldMapping.CanInsert)
                    .Update(fieldMapping.CanUpdate)
                    .NativeType(fieldMapping.NativeType)
                    .Key(fieldMapping.IsKey);
            }

            return mergeDefinition;
        }