DataTableMapping.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // System.Data.Common.DataTableMapping.cs
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // (C) Ximian, Inc
  9. // Copyright (C) Tim Coleman, 2002-2003
  10. //
  11. using System.ComponentModel;
  12. using System.Data;
  13. namespace System.Data.Common {
  14. [TypeConverterAttribute (typeof (DataTableMappingConverter))]
  15. public sealed class DataTableMapping : MarshalByRefObject, ITableMapping, ICloneable
  16. {
  17. #region Fields
  18. string sourceTable;
  19. string dataSetTable;
  20. DataColumnMappingCollection columnMappings;
  21. #endregion // Fields
  22. #region Constructors
  23. public DataTableMapping ()
  24. {
  25. dataSetTable = String.Empty;
  26. sourceTable = String.Empty;
  27. columnMappings = new DataColumnMappingCollection ();
  28. }
  29. public DataTableMapping (string sourceTable, string dataSetTable)
  30. : this ()
  31. {
  32. this.sourceTable = sourceTable;
  33. this.dataSetTable = dataSetTable;
  34. }
  35. public DataTableMapping (string sourceTable, string dataSetTable, DataColumnMapping[] columnMappings)
  36. : this (sourceTable, dataSetTable)
  37. {
  38. this.columnMappings.AddRange (columnMappings);
  39. }
  40. #endregion // Constructors
  41. #region Properties
  42. [DataSysDescription ("Individual columns mappings when this table mapping is matched.")]
  43. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  44. public DataColumnMappingCollection ColumnMappings {
  45. get { return columnMappings; }
  46. }
  47. [DataSysDescription ("DataTable.TableName")]
  48. [DefaultValue ("")]
  49. public string DataSetTable {
  50. get { return dataSetTable; }
  51. set { dataSetTable = value; }
  52. }
  53. IColumnMappingCollection ITableMapping.ColumnMappings {
  54. get { return ColumnMappings; }
  55. }
  56. [DataSysDescription ("The DataTableMapping source table name. This name is case sensitive.")]
  57. [DefaultValue ("")]
  58. public string SourceTable {
  59. get { return sourceTable; }
  60. set { sourceTable = value; }
  61. }
  62. #endregion // Properties
  63. #region Methods
  64. [EditorBrowsable (EditorBrowsableState.Advanced)]
  65. public DataColumnMapping GetColumnMappingBySchemaAction (string sourceColumn, MissingMappingAction mappingAction)
  66. {
  67. return DataColumnMappingCollection.GetColumnMappingBySchemaAction (columnMappings, sourceColumn, mappingAction);
  68. }
  69. #if NET_1_2
  70. [MonoTODO]
  71. public DataColumn GetDataColumn (string sourceColumn, Type dataType, DataTable dataTable, MissingMappingAction mappingAction, MissingSchemaAction schemaAction)
  72. {
  73. throw new NotImplementedException ();
  74. }
  75. #endif
  76. [EditorBrowsable (EditorBrowsableState.Advanced)]
  77. public DataTable GetDataTableBySchemaAction (DataSet dataSet, MissingSchemaAction schemaAction)
  78. {
  79. if (dataSet.Tables.Contains (DataSetTable))
  80. return dataSet.Tables [DataSetTable];
  81. if (schemaAction == MissingSchemaAction.Ignore)
  82. return null;
  83. if (schemaAction == MissingSchemaAction.Error)
  84. throw new InvalidOperationException (String.Format ("Missing the '{0} DataTable for the '{1}' SourceTable", DataSetTable, SourceTable));
  85. return new DataTable (DataSetTable);
  86. }
  87. object ICloneable.Clone ()
  88. {
  89. return new DataTableMapping (SourceTable, DataSetTable);
  90. }
  91. public override string ToString ()
  92. {
  93. return SourceTable;
  94. }
  95. #endregion // Methods
  96. }
  97. }