2 // System.Data.Common.DataTableMapping.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
9 // Copyright (C) Tim Coleman, 2002-2003
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.ComponentModel;
38 namespace System.Data.Common {
39 [TypeConverterAttribute (typeof (DataTableMappingConverter))]
40 public sealed class DataTableMapping : MarshalByRefObject, ITableMapping, ICloneable
46 DataColumnMappingCollection columnMappings;
52 public DataTableMapping ()
54 dataSetTable = String.Empty;
55 sourceTable = String.Empty;
56 columnMappings = new DataColumnMappingCollection ();
59 public DataTableMapping (string sourceTable, string dataSetTable)
62 this.sourceTable = sourceTable;
63 this.dataSetTable = dataSetTable;
66 public DataTableMapping (string sourceTable, string dataSetTable, DataColumnMapping[] columnMappings)
67 : this (sourceTable, dataSetTable)
69 this.columnMappings.AddRange (columnMappings);
72 #endregion // Constructors
76 [DataSysDescription ("Individual columns mappings when this table mapping is matched.")]
77 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
78 public DataColumnMappingCollection ColumnMappings {
79 get { return columnMappings; }
82 [DataSysDescription ("DataTable.TableName")]
84 public string DataSetTable {
85 get { return dataSetTable; }
86 set { dataSetTable = value; }
89 IColumnMappingCollection ITableMapping.ColumnMappings {
90 get { return ColumnMappings; }
93 [DataSysDescription ("The DataTableMapping source table name. This name is case sensitive.")]
95 public string SourceTable {
96 get { return sourceTable; }
97 set { sourceTable = value; }
100 #endregion // Properties
104 [EditorBrowsable (EditorBrowsableState.Advanced)]
105 public DataColumnMapping GetColumnMappingBySchemaAction (string sourceColumn, MissingMappingAction mappingAction)
107 return DataColumnMappingCollection.GetColumnMappingBySchemaAction (columnMappings, sourceColumn, mappingAction);
112 public DataColumn GetDataColumn (string sourceColumn, Type dataType, DataTable dataTable, MissingMappingAction mappingAction, MissingSchemaAction schemaAction)
114 throw new NotImplementedException ();
118 [EditorBrowsable (EditorBrowsableState.Advanced)]
119 public DataTable GetDataTableBySchemaAction (DataSet dataSet, MissingSchemaAction schemaAction)
121 if (dataSet.Tables.Contains (DataSetTable))
122 return dataSet.Tables [DataSetTable];
123 if (schemaAction == MissingSchemaAction.Ignore)
125 if (schemaAction == MissingSchemaAction.Error)
126 throw new InvalidOperationException (String.Format ("Missing the '{0} DataTable for the '{1}' SourceTable", DataSetTable, SourceTable));
127 return new DataTable (DataSetTable);
130 object ICloneable.Clone ()
132 DataColumnMapping [] arr = new DataColumnMapping [columnMappings.Count];
133 columnMappings.CopyTo (arr, 0);
134 return new DataTableMapping (SourceTable, DataSetTable, arr);
137 public override string ToString ()
142 #endregion // Methods