Export (0) Print
Expand All

ConstraintCollection Class

Represents a collection of constraints for a DataTable.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

[<Sealed>]
type ConstraintCollection =  
    class 
        inherit InternalDataCollectionBase 
    end

The ConstraintCollection type exposes the following members.

  NameDescription
Public propertySupported by the XNA FrameworkCountGets the total number of elements in a collection. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkIsReadOnlyGets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkIsSynchronizedGets a value that indicates whether the InternalDataCollectionBase is synchonized. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkItem(Int32)Gets the Constraint from the collection at the specified index.
Public propertySupported by the XNA FrameworkItem(String)Gets the Constraint from the collection with the specified name.
Public propertySupported by the XNA FrameworkSyncRootGets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase.)
Top

  NameDescription
Public methodSupported by the XNA FrameworkAdd(Constraint)Adds the specified Constraint object to the collection.
Public methodSupported by the XNA FrameworkAdd(String, DataColumn, Boolean)Constructs a new UniqueConstraint with the specified name, DataColumn, and value that indicates whether the column is a primary key, and adds it to the collection.
Public methodSupported by the XNA FrameworkAdd(String, DataColumn, DataColumn)Constructs a new ForeignKeyConstraint with the specified name, parent column, and child column, and adds the constraint to the collection.
Public methodSupported by the XNA FrameworkAdd(String, DataColumn[], Boolean)Constructs a new UniqueConstraint with the specified name, array of DataColumn objects, and value that indicates whether the column is a primary key, and adds it to the collection.
Public methodSupported by the XNA FrameworkAdd(String, DataColumn[], DataColumn[])Constructs a new ForeignKeyConstraint, with the specified arrays of parent columns and child columns, and adds the constraint to the collection.
Public methodSupported by the XNA FrameworkAddRangeCopies the elements of the specified ConstraintCollection array to the end of the collection.
Public methodSupported by the XNA FrameworkCanRemoveIndicates whether a Constraint can be removed.
Public methodSupported by the XNA FrameworkClearClears the collection of any Constraint objects.
Public methodSupported by the XNA FrameworkContainsIndicates whether the Constraint object specified by name exists in the collection.
Public methodSupported by the XNA FrameworkCopyTo(Array, Int32)Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index. (Inherited from InternalDataCollectionBase.)
Public methodSupported by the XNA FrameworkCopyTo(Constraint[], Int32)Copies the collection objects to a one-dimensional Array instance starting at the specified index.
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetEnumeratorGets an IEnumerator for the collection. (Inherited from InternalDataCollectionBase.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkIndexOf(Constraint)Gets the index of the specified Constraint.
Public methodSupported by the XNA FrameworkIndexOf(String)Gets the index of the Constraint specified by name.
Public methodSupported by the XNA FrameworkRemove(Constraint)Removes the specified Constraint from the collection.
Public methodSupported by the XNA FrameworkRemove(String)Removes the Constraint object specified by name from the collection.
Public methodSupported by the XNA FrameworkRemoveAtRemoves the Constraint object at the specified index from the collection.
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventSupported by the XNA FrameworkCollectionChangedOccurs whenever the ConstraintCollection is changed because of Constraint objects being added or removed.
Top

The ConstraintCollection is accessed through the DataTable.Constraints property.

The ConstraintCollection can contain both UniqueConstraint and ForeignKeyConstraint objects for the DataTable. A UniqueConstraint object makes sure that data in a specific column is always unique to preserve the data integrity. The ForeignKeyConstraint determines what will occur in related tables when data in the DataTable is either updated or deleted. For example, if a row is deleted, the ForeignKeyConstraint will determine whether the related rows are also deleted (a cascade), or some other course of action.

NoteNote

When you add a DataRelation that creates a relationship between two tables to a DataSet, both a ForeignKeyConstraint and a UniqueConstraint are created automatically. The UniqueConstraint is applied to the primary key column in the parent DataTable, and the constraint is added to that table's ConstraintCollection. The ForeignKeyConstraint is applied to the primary key column and the foreign key column, and the constraint is added to the child table's ConstraintCollection.

The ConstraintCollection uses standard collection methods such as Add, Clear, and Remove. In addition, the Contains method can be used to look for the existence of a particular constraint in the collection.

A UniqueConstraint is created when a DataColumn with its Unique property set to true is added to a DataTable object's DataColumnCollection.

A ForeignKeyConstraint is created when a DataRelation is added to a DataSet object's DataRelationCollection.

The first example creates a DataTable, and adds a DataColumn (with its Unique property set to true) to the DataColumnCollection. The second example creates a DataSet, two DataTable objects, four columns, and a DataRelation. The count of constraints is then printed to show that a ForeignKeyConstraint and a UniqueConstraint are created when a DataRelation is added to the DataSet object's DataRelationCollection.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

This type is safe for multithreaded read operations. You must synchronize any write operations.

Show:
© 2014 Microsoft