System.Data.Common.DataColumnMappingCollection.GetColumnMappingBySchemaAction C# (CSharp) Method

GetColumnMappingBySchemaAction() private method

private GetColumnMappingBySchemaAction ( DataColumnMappingCollection columnMappings, string sourceColumn, MissingMappingAction mappingAction ) : DataColumnMapping
columnMappings DataColumnMappingCollection
sourceColumn string
mappingAction MissingMappingAction
return DataColumnMapping
        public static DataColumnMapping GetColumnMappingBySchemaAction(DataColumnMappingCollection columnMappings, string sourceColumn, MissingMappingAction mappingAction)
        {
            if (null != columnMappings)
            {
                int index = columnMappings.IndexOf(sourceColumn);
                if (-1 != index)
                {
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceInfo)
                    {
                        Debug.WriteLine($"mapping match on SourceColumn \"{sourceColumn}\"");
                    }
#endif
                    return columnMappings._items[index];
                }
            }
            if (string.IsNullOrEmpty(sourceColumn))
            {
                throw ADP.InvalidSourceColumn(nameof(sourceColumn));
            }
            switch (mappingAction)
            {
                case MissingMappingAction.Passthrough:
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceInfo)
                    {
                        Debug.WriteLine($"mapping passthrough of SourceColumn \"{sourceColumn}\"");
                    }
#endif
                    return new DataColumnMapping(sourceColumn, sourceColumn);

                case MissingMappingAction.Ignore:
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceWarning)
                    {
                        Debug.WriteLine($"mapping filter of SourceColumn \"{sourceColumn}\"");
                    }
#endif
                    return null;

                case MissingMappingAction.Error:
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceError)
                    {
                        Debug.WriteLine($"mapping error on SourceColumn \"{sourceColumn}\"");
                    }
#endif
                    throw ADP.MissingColumnMapping(sourceColumn);
            }
            throw ADP.InvalidMissingMappingAction(mappingAction);
        }
    }

Usage Example

Esempio n. 1
0
        public int Update(DataSet dataSet, string srcTable)
        {
            MissingMappingAction mappingAction = MissingMappingAction;

            if (mappingAction == MissingMappingAction.Ignore)
            {
                mappingAction = MissingMappingAction.Error;
            }

            DataTableMapping tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(TableMappings, srcTable, srcTable, mappingAction);

            DataTable dataTable = dataSet.Tables [tableMapping.DataSetTable];

            if (dataTable == null)
            {
                throw new ArgumentException(String.Format("Missing table {0}",
                                                          srcTable));
            }

            /** Copied from another Update function **/
            if (tableMapping != null)
            {
                foreach (DataColumn col in dataTable.Columns)
                {
                    if (tableMapping.ColumnMappings.IndexOf(col.ColumnName) >= 0)
                    {
                        continue;
                    }
                    DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings, col.ColumnName, MissingMappingAction);
                    if (columnMapping == null)
                    {
                        columnMapping = new DataColumnMapping(col.ColumnName, col.ColumnName);
                    }
                    tableMapping.ColumnMappings.Add(columnMapping);
                }
            }
            else
            {
                ArrayList cmc = new ArrayList();
                foreach (DataColumn col in dataTable.Columns)
                {
                    cmc.Add(new DataColumnMapping(col.ColumnName, col.ColumnName));
                }
                tableMapping =
                    new DataTableMapping(
                        dataTable.TableName,
                        dataTable.TableName,
                        cmc.ToArray(typeof(DataColumnMapping)) as DataColumnMapping []);
            }
            /**end insert from another update**/
            return(Update(dataTable, tableMapping));
        }
All Usage Examples Of System.Data.Common.DataColumnMappingCollection::GetColumnMappingBySchemaAction