ConstraintCollection.AddRange(Constraint[]) 메서드

정의

지정된 ConstraintCollection 배열의 요소를 컬렉션의 끝에 복사합니다.

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

매개 변수

constraints
Constraint[]

컬렉션에 추가할 ConstraintCollection 개체의 배열입니다.

예제

다음 예제에서는 기본 및 외래 키 제약 조건을 만들고 에 추가합니다 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 New UniqueConstraint( _
            customersTable.Columns("CustomerID"))
        Dim fkConstraint As 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 {ex.GetType()} occurred.")
    End Try
End Sub

설명

가 호출된 경우 BeginInitAddRange 가 호출될 때까지 EndInit 컬렉션에 개체를 추가하지 않습니다. 호출될 EndInit 때 컬렉션은 에 대한 가장 최근 호출 AddRange에 지정된 항목으로 채워집니다. 가 시퀀스 내에서EndInitBeginInit / 여러 번 호출되는 경우 AddRange 에 대한 가장 최근 호출 AddRange 에 지정된 항목만 추가됩니다.

적용 대상