System.Data.Common.DataTableMapping.GetDataTableBySchemaAction C# (CSharp) Метод

GetDataTableBySchemaAction() приватный Метод

private GetDataTableBySchemaAction ( DataSet dataSet, MissingSchemaAction schemaAction ) : DataTable
dataSet System.Data.DataSet
schemaAction MissingSchemaAction
Результат System.Data.DataTable
        public DataTable GetDataTableBySchemaAction(DataSet dataSet, MissingSchemaAction schemaAction)
        {
            if (null == dataSet)
            {
                throw ADP.ArgumentNull(nameof(dataSet));
            }
            string dataSetTable = DataSetTable;

            if (string.IsNullOrEmpty(dataSetTable))
            {
#if DEBUG
                if (AdapterSwitches.DataSchema.TraceWarning)
                {
                    Debug.WriteLine("explicit filtering of SourceTable \"" + SourceTable + "\"");
                }
#endif
                return null;
            }
            DataTableCollection tables = dataSet.Tables;
            int index = tables.IndexOf(dataSetTable);
            if ((0 <= index) && (index < tables.Count))
            {
#if DEBUG
                if (AdapterSwitches.DataSchema.TraceInfo)
                {
                    Debug.WriteLine("schema match on DataTable \"" + dataSetTable);
                }
#endif
                return tables[index];
            }
            switch (schemaAction)
            {
                case MissingSchemaAction.Add:
                case MissingSchemaAction.AddWithKey:
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceInfo)
                    {
                        Debug.WriteLine("schema add of DataTable \"" + dataSetTable + "\"");
                    }
#endif
                    return new DataTable(dataSetTable);

                case MissingSchemaAction.Ignore:
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceWarning)
                    {
                        Debug.WriteLine("schema filter of DataTable \"" + dataSetTable + "\"");
                    }
#endif
                    return null;

                case MissingSchemaAction.Error:
#if DEBUG
                    if (AdapterSwitches.DataSchema.TraceError)
                    {
                        Debug.WriteLine("schema error on DataTable \"" + dataSetTable + "\"");
                    }
#endif
                    throw ADP.MissingTableSchema(dataSetTable, SourceTable);
            }
            throw ADP.InvalidMissingSchemaAction(schemaAction);
        }

Usage Example

Пример #1
0
        internal void SetupSchema(SchemaType schemaType, string sourceTableName, bool gettingData, DataColumn parentChapterColumn, object parentChapterValue)
        {
#if DEBUG
            Debug.Assert(null != this.dataSet || null != this.dataTable, "SetupSchema - null dataSet");
            Debug.Assert(SchemaType.Mapped == schemaType || SchemaType.Source == schemaType, "SetupSchema - invalid schemaType");
#endif
            MissingMappingAction mappingAction;
            MissingSchemaAction  schemaAction;

            if (SchemaType.Mapped == schemaType)
            {
                mappingAction = this.adapter.MissingMappingAction;
                schemaAction  = this.adapter.MissingSchemaAction;
                if (!ADP.IsEmpty(sourceTableName))   // MDAC 66034
                {
                    tableMapping = this.adapter.GetTableMappingBySchemaAction(sourceTableName, sourceTableName, mappingAction);
                }
                else if (null != this.dataTable)
                {
                    int index = this.adapter.IndexOfDataSetTable(this.dataTable.TableName);
                    if (-1 != index)
                    {
                        tableMapping = this.adapter.TableMappings[index];
                    }
                    else
                    {
                        switch (mappingAction)
                        {
                        case MissingMappingAction.Passthrough:
                            tableMapping = new DataTableMapping(this.dataTable.TableName, this.dataTable.TableName);
                            break;

                        case MissingMappingAction.Ignore:
                            tableMapping = null;
                            break;

                        case MissingMappingAction.Error:
                            throw ADP.MissingTableMappingDestination(this.dataTable.TableName);

                        default:
                            throw ADP.InvalidMappingAction((int)mappingAction);
                        }
                    }
                }
            }
            else if (SchemaType.Source == schemaType)
            {
                mappingAction = System.Data.MissingMappingAction.Passthrough;
                schemaAction  = Data.MissingSchemaAction.Add;
                if (!ADP.IsEmpty(sourceTableName))   // MDAC 66034
                {
                    tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(null, sourceTableName, sourceTableName, mappingAction);
                }
                else if (null != this.dataTable)
                {
                    int index = this.adapter.IndexOfDataSetTable(this.dataTable.TableName); // MDAC 66034
                    if (-1 != index)
                    {
                        tableMapping = this.adapter.TableMappings[index];
                    }
                    else
                    {
                        tableMapping = new DataTableMapping(this.dataTable.TableName, this.dataTable.TableName);
                    }
                }
            }
            else
            {
                throw ADP.InvalidSchemaType((int)schemaType);
            }
            if (null == tableMapping)
            {
                return;
            }
            if (null == this.dataTable)
            {
                this.dataTable = tableMapping.GetDataTableBySchemaAction(this.dataSet, schemaAction);
                if (null == this.dataTable)
                {
                    return; // null means ignore (mapped to nothing)
                }
            }

            if (null == this.schemaTable)
            {
                SetupSchemaWithoutKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
            }
            else
            {
                SetupSchemaWithKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
            }
        }