DataColumn.ColumnMapping Propriedade

Definição

Obtém ou define o MappingType da coluna.Gets or sets the MappingType of the column.

public:
 virtual property System::Data::MappingType ColumnMapping { System::Data::MappingType get(); void set(System::Data::MappingType value); };
public virtual System.Data.MappingType ColumnMapping { get; set; }
[System.Data.DataSysDescription("DataColumnMappingDescr")]
public virtual System.Data.MappingType ColumnMapping { get; set; }
member this.ColumnMapping : System.Data.MappingType with get, set
[<System.Data.DataSysDescription("DataColumnMappingDescr")>]
member this.ColumnMapping : System.Data.MappingType with get, set
Public Overridable Property ColumnMapping As MappingType

Valor da propriedade

MappingType

Um dos valores de MappingType.One of the MappingType values.

Atributos

Exemplos

O exemplo a seguir define a ColumnMapping Propriedade Type de New DataColumn .The following example sets the ColumnMapping type property of new DataColumn.

private void AddColumn(DataTable table)
{
    // Create a new column and set its properties.
    DataColumn column = new DataColumn("column",
        typeof(int), "", MappingType.Attribute);
    column.DataType = Type.GetType("System.String");
    column.ColumnMapping = MappingType.Element;

    // Add the column the table's columns collection.
    table.Columns.Add(column);
}
Private Sub AddColumn(table As DataTable )
    ' Create a new column and set its properties.
    Dim column As New DataColumn("ID", _
        Type.GetType("System.Int32"), "", MappingType.Attribute)
    column.DataType = Type.GetType("System.String")
    column.ColumnMapping = MappingType.Element

    ' Add the column the table's columns collection.
    table.Columns.Add(column)
End Sub

Comentários

A ColumnMapping propriedade determina como um DataColumn é mapeado quando um DataSet é salvo como um documento XML usando o WriteXml método.The ColumnMapping property determines how a DataColumn is mapped when a DataSet is saved as an XML document using the WriteXml method.

Por exemplo, se um DataColumn for chamado "CustomerID" e sua ColumnMapping propriedade for definida como MappingType.Element , o valor da coluna produzirá o seguinte XML:For example, if a DataColumn is named "customerID," and its ColumnMapping property is set to MappingType.Element, the column value will produce the following XML:

<Customers>  
 <customerID>ALFKI</customerID>  
......  
 </Customers>  
 <Orders>  
 <OrderID>12345</OrderID>  
 <customerID>ALFKI</customerID>  
......  
 </Orders>  

No entanto, se a mesma coluna for mapeada para MappingType.Attribute , o seguinte XML será produzido:However, if the same column is mapped to MappingType.Attribute, the following XML is produced:

<Customers customerID="ALFKI"........more attributes.....>  
 <Order orderID="1234"....more attributes..../>  
 <Order orderID="1234"....more attributes..../>  
...... More orders for this customer  
 </Customers>  

Use o DataColumn Construtor que contém o type argumento para especificar como o DataColumn é mapeado quando seu DataSet é transformado em um documento XML.Use the DataColumn constructor that contains the type argument to specify how the DataColumn is mapped when its DataSet is transformed to an XML document.

A ColumnMapping propriedade corresponde ao argumento do construtor type .The ColumnMapping property corresponds to the constructor argument type.

Aplica-se a