ConstraintCollection.AddRange(Constraint[]) ConstraintCollection.AddRange(Constraint[]) ConstraintCollection.AddRange(Constraint[]) ConstraintCollection.AddRange(Constraint[]) Method

Definizione

Copia gli elementi della matrice di oggetti ConstraintCollection specificata alla fine dell'insieme.Copies the elements of the specified ConstraintCollection array to the end of the collection.

public:
 void AddRange(cli::array <System::Data::Constraint ^> ^ constraints);
public void AddRange (System.Data.Constraint[] constraints);
member this.AddRange : System.Data.Constraint[] -> unit
Public Sub AddRange (constraints As Constraint())

Parametri

constraints
Constraint[]

Matrice di oggetti ConstraintCollection da aggiungere alla raccolta.An array of ConstraintCollection objects to add to the collection.

Esempi

Nell'esempio seguente vengono creati vincoli di chiave primaria ed esterna e vengono aggiunti a ConstraintCollection.The following example creates primary and foreign key constraints, and adds them to the ConstraintCollection.

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());
    }
}
Public Shared Sub ConstraintAddRange(dataSet As DataSet)
	Try
		' Reference the tables from the DataSet.
		Dim customersTable As DataTable = dataSet.Tables("Customers")
		Dim ordersTable As DataTable = dataSet.Tables("Orders")

		' Create unique and foreign key constraints.
		Dim uniqueConstraint As UniqueConstraint = New _
            UniqueConstraint(customersTable.Columns("CustomerID"))
		Dim fkConstraint As ForeignKeyConstraint = New _
            ForeignKeyConstraint("CustOrdersConstraint", _
            customersTable.Columns("CustomerID"), _
            ordersTable.Columns("CustomerID"))

		' Add the constraints.
		customersTable.Constraints.AddRange(New Constraint() _
            {uniqueConstraint, fkConstraint})

	Catch ex As Exception
		' Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.", _
        ex.GetType().ToString())
	End Try
End Sub

Commenti

Se BeginInit è stato chiamato, AddRange non aggiunge alcun oggetto alla raccolta finché non EndInit viene chiamato il metodo.If BeginInit has been called, AddRange does not add any objects to the collection until EndInit is called. Quando viene chiamato, la raccolta viene popolata con gli elementi specificati nella chiamata più recente a AddRange. EndInitAt the time that EndInit is called, the collection will be populated with the items specified in the most recent call to AddRange. Se AddRange viene chiamato più volte all'interno BeginInit di una / EndInit sequenza, vengono aggiunti solo gli elementi specificati nella chiamata AddRange più recente a.If AddRange is called multiple times within a BeginInit / EndInit sequence, only those items specified in the most recent call to AddRange are added.

Si applica a