DataColumn.ColumnMapping Proprietà

Definizione

Ottiene o imposta l'oggetto MappingType della colonna.

C#
public virtual System.Data.MappingType ColumnMapping { get; set; }
C#
[System.Data.DataSysDescription("DataColumnMappingDescr")]
public virtual System.Data.MappingType ColumnMapping { get; set; }

Valore della proprietà

Uno dei valori di MappingType.

Attributi

Esempio

Nell'esempio seguente viene impostata la ColumnMapping proprietà type di new DataColumn.

C#
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);
}

Commenti

La ColumnMapping proprietà determina la modalità di mapping di un DataColumn oggetto quando un DataSet oggetto viene salvato come documento XML utilizzando il WriteXml metodo .

Ad esempio, se un DataColumn oggetto è denominato "customerID" e la relativa ColumnMapping proprietà è impostata su MappingType.Element, il valore della colonna produrrà il codice XML seguente:

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

Tuttavia, se viene eseguito il mapping della stessa colonna a MappingType.Attribute, viene generato il codice XML seguente:

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

Utilizzare il DataColumn costruttore che contiene l'argomento type per specificare la modalità di mapping dell'oggetto DataColumn quando viene DataSet trasformato in un documento XML.

La ColumnMapping proprietà corrisponde all'argomento typedel costruttore .

Si applica a

Prodotto Versioni
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Vedi anche