ForeignKeyConstraint.Equals(Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示当前的 ForeignKeyConstraint 是否与指定对象相同。
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
参数
- key
- Object
此 ForeignKeyConstraint 将与之比较的对象。 如果两个 ForeignKeyConstraint 约束相同的列,则它们相等。
返回
如果对象相同,则为 true
;否则为 false
。
示例
以下示例创建一个新的 ForeignKeyConstraint ,并在将它添加到 ConstraintCollection之前,使用 Equals 方法检查它与其他集合成员。
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