DataRelation.ChildKeyConstraint Property

Definition

Gets the ForeignKeyConstraint for the relation.

C#
public virtual System.Data.ForeignKeyConstraint? ChildKeyConstraint { get; }
C#
public virtual System.Data.ForeignKeyConstraint ChildKeyConstraint { get; }

Property Value

A ForeignKeyConstraint.

Examples

The following example sets the UpdateRule, DeleteRule, and AcceptReject rule for the ForeignKeyConstraint associated with the DataRelation.

VB
Private Sub SetChildKeyConstraint(dataSet As DataSet)
   ' Set child and parent columns.
   Dim parentColumn As DataColumn = dataSet.Tables( _
       "Suppliers").Columns("SupplierID")
   Dim childColumn As DataColumn = dataSet.Tables( _
       "Products").Columns("SupplierID")
   Dim relation As New DataRelation( _
       "SuppliersConstraint", parentColumn, childColumn)
   dataSet.Relations.Add(relation)

   Dim foreignKey As ForeignKeyConstraint = _
       relation.ChildKeyConstraint
   foreignKey.DeleteRule = Rule.SetNull
   foreignKey.UpdateRule = Rule.Cascade
   foreignKey.AcceptRejectRule = AcceptRejectRule.Cascade
End Sub

Remarks

If no associated ForeignKeyConstraint exists for this relationship, it will be created automatically, and pointed to by the ChildKeyConstraint, when the relation is added to the collection of relations.

Applies to

Product Versions
.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

See also