System.Data.ProviderBase.SchemaMapping.SchemaMapping C# (CSharp) Method

SchemaMapping() private method

private SchemaMapping ( DataAdapter adapter, DataSet dataset, DataTable datatable, DataReaderContainer dataReader, bool keyInfo, SchemaType schemaType, string sourceTableName, bool gettingData, DataColumn parentChapterColumn, object parentChapterValue ) : System.Collections.Generic
adapter System.Data.Common.DataAdapter
dataset DataSet
datatable DataTable
dataReader DataReaderContainer
keyInfo bool
schemaType SchemaType
sourceTableName string
gettingData bool
parentChapterColumn DataColumn
parentChapterValue object
return System.Collections.Generic
        internal SchemaMapping(DataAdapter adapter, DataSet dataset, DataTable datatable, DataReaderContainer dataReader, bool keyInfo,
                                    SchemaType schemaType, string sourceTableName, bool gettingData,
                                    DataColumn parentChapterColumn, object parentChapterValue)
        {
            Debug.Assert(null != adapter, nameof(adapter));
            Debug.Assert(null != dataReader, nameof(dataReader));
            Debug.Assert(0 < dataReader.FieldCount, "FieldCount");
            Debug.Assert(null != dataset || null != datatable, "SchemaMapping - null dataSet");
            Debug.Assert(SchemaType.Mapped == schemaType || SchemaType.Source == schemaType, "SetupSchema - invalid schemaType");

            _dataSet = dataset;     // setting DataSet implies chapters are supported
            _dataTable = datatable; // setting only DataTable, not DataSet implies chapters are not supported
            _adapter = adapter;
            _dataReader = dataReader;

            if (keyInfo)
            {
                _schemaTable = dataReader.GetSchemaTable();
            }

            if (adapter.ShouldSerializeFillLoadOption())
            {
                _loadOption = adapter.FillLoadOption;
            }
            else if (adapter.AcceptChangesDuringFill)
            {
                _loadOption = (LoadOption)4; // true
            }
            else
            {
                _loadOption = (LoadOption)5; //false
            }

            MissingMappingAction mappingAction;
            MissingSchemaAction schemaAction;
            if (SchemaType.Mapped == schemaType)
            {
                mappingAction = _adapter.MissingMappingAction;
                schemaAction = _adapter.MissingSchemaAction;
                if (!string.IsNullOrEmpty(sourceTableName))
                {
                    _tableMapping = _adapter.GetTableMappingBySchemaAction(sourceTableName, sourceTableName, mappingAction);
                }
                else if (null != _dataTable)
                {
                    int index = _adapter.IndexOfDataSetTable(_dataTable.TableName);
                    if (-1 != index)
                    {
                        _tableMapping = _adapter.TableMappings[index];
                    }
                    else
                    {
                        switch (mappingAction)
                        {
                            case MissingMappingAction.Passthrough:
                                _tableMapping = new DataTableMapping(_dataTable.TableName, _dataTable.TableName);
                                break;
                            case MissingMappingAction.Ignore:
                                _tableMapping = null;
                                break;
                            case MissingMappingAction.Error:
                                throw ADP.MissingTableMappingDestination(_dataTable.TableName);
                            default:
                                throw ADP.InvalidMissingMappingAction(mappingAction);
                        }
                    }
                }
            }
            else if (SchemaType.Source == schemaType)
            {
                mappingAction = System.Data.MissingMappingAction.Passthrough;
                schemaAction = Data.MissingSchemaAction.Add;
                if (!string.IsNullOrEmpty(sourceTableName))
                {
                    _tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(null, sourceTableName, sourceTableName, mappingAction);
                }
                else if (null != _dataTable)
                {
                    int index = _adapter.IndexOfDataSetTable(_dataTable.TableName);
                    if (-1 != index)
                    {
                        _tableMapping = _adapter.TableMappings[index];
                    }
                    else
                    {
                        _tableMapping = new DataTableMapping(_dataTable.TableName, _dataTable.TableName);
                    }
                }
            }
            else
            {
                throw ADP.InvalidSchemaType(schemaType);
            }

            if (null != _tableMapping)
            {
                if (null == _dataTable)
                {
                    _dataTable = _tableMapping.GetDataTableBySchemaAction(_dataSet, schemaAction);
                }
                if (null != _dataTable)
                {
                    _fieldNames = GenerateFieldNames(dataReader);

                    if (null == _schemaTable)
                    {
                        _readerDataValues = SetupSchemaWithoutKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
                    }
                    else
                    {
                        _readerDataValues = SetupSchemaWithKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
                    }
                }
                // else (null == _dataTable) which means ignore (mapped to nothing)
            }
        }