ConstraintCollection.AddRange(Constraint[]) Método

Definición

Copia los elementos de la matriz ConstraintCollection especificada al final de la colección.

C#
public void AddRange (System.Data.Constraint[]? constraints);
C#
public void AddRange (System.Data.Constraint[] constraints);

Parámetros

constraints
Constraint[]

Matriz de objetos ConstraintCollection que se agregará a la colección.

Ejemplos

En el ejemplo siguiente se crean restricciones de clave principal y externa, y se agregan a .ConstraintCollection

C#
public static void ConstraintAddRange(DataSet dataSet)
{
    try
    {
        // Reference the tables from the DataSet.
        DataTable customersTable = dataSet.Tables["Customers"];
        DataTable ordersTable = dataSet.Tables["Orders"];

        // Create unique and foreign key constraints.
        UniqueConstraint uniqueConstraint = new
            UniqueConstraint(customersTable.Columns["CustomerID"]);
        ForeignKeyConstraint fkConstraint = new
            ForeignKeyConstraint("CustOrdersConstraint",
            customersTable.Columns["CustomerID"],
            ordersTable.Columns["CustomerID"]);

        // Add the constraints.
        customersTable.Constraints.AddRange(new Constraint[]
            {uniqueConstraint, fkConstraint});
    }
    catch(Exception ex)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            ex.GetType());
    }
}

Comentarios

Si BeginInit se ha llamado a , AddRange no agrega ningún objeto a la colección hasta EndInit que se llama a . En el momento en que EndInit se llama, la colección se rellenará con los elementos especificados en la llamada más reciente a AddRange. Si AddRange se llama varias veces dentro de unaEndInitBeginInit / secuencia, solo se agregan los elementos especificados en la llamada más reciente a .AddRange

Se aplica a

Producto Versiones
.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