Compartilhar via


ForeignKeyConstraint.Equals(Object) Método

Definição

Obtém um valor que indica se o ForeignKeyConstraint atual é idêntico ao objeto especificado.

public:
 override bool Equals(System::Object ^ key);
public override bool Equals (object? key);
public override bool Equals (object key);
override this.Equals : obj -> bool
Public Overrides Function Equals (key As Object) As Boolean

Parâmetros

key
Object

O objeto ao qual este ForeignKeyConstraint é comparado. Dois ForeignKeyConstraint são iguais se eles restringem as mesmas colunas.

Retornos

true se os objetos forem iguais; caso contrário, false.

Exemplos

O exemplo a seguir cria um novo ForeignKeyConstraint e verifica-o em relação a outros membros da coleção com o Equals método antes de adicioná-lo a um ConstraintCollection.

private void CreateConstraint(DataSet dataSet)
{
   // Create the ForignKeyConstraint with two DataColumn objects.
   DataColumn parentCol = dataSet.Tables["Customers"].Columns["id"];
   DataColumn childCol = dataSet.Tables["Orders"].Columns["OrderID"];
   ForeignKeyConstraint fkeyConstraint =
      new ForeignKeyConstraint("fkConstraint", parentCol, childCol);

   // Test against existing members using the Equals method.
   foreach(ForeignKeyConstraint testConstraint in
       dataSet.Tables["Orders"].Constraints)
   {
      if(fkeyConstraint.Equals(testConstraint)){
         Console.WriteLine("Identical ForeignKeyConstraint!");
          // Insert code to delete the duplicate object,
          // or stop the procedure.
      }
   }
}
Private Sub CreateConstraint(dataSet As DataSet)
    ' Create the ForignKeyConstraint with two DataColumn objects.
    Dim parentCol As DataColumn = _
       dataSet.Tables("Customers").Columns("id")
    Dim childCol As DataColumn = _
       dataSet.Tables("Orders").Columns("OrderID")
    Dim fkeyConstraint As _
       New ForeignKeyConstraint("fkConstraint", parentCol, childCol)

    ' Test against existing members using the Equals method.
    Dim testConstraint As ForeignKeyConstraint
    For Each testConstraint In  dataSet.Tables("Orders").Constraints
        If fkeyConstraint.Equals(testConstraint) Then
            Console.WriteLine("Identical ForeignKeyConstraint!")
            ' Insert code to delete the duplicate object, 
            ' or stop the procedure.
        End If
    Next testConstraint
End Sub

Aplica-se a