UniqueConstraint UniqueConstraint UniqueConstraint UniqueConstraint Class

定义

表示对一组列的限制,列中的所有值必须是唯一的。Represents a restriction on a set of columns in which all values must be unique.

public ref class UniqueConstraint : System::Data::Constraint
[System.Serializable]
public class UniqueConstraint : System.Data.Constraint
type UniqueConstraint = class
    inherit Constraint
Public Class UniqueConstraint
Inherits Constraint
继承
UniqueConstraintUniqueConstraintUniqueConstraintUniqueConstraint
属性

示例

下面的示例将添加UniqueConstraint DataSet到, 并将EnforceConstraints属性设置为trueThe following example adds a UniqueConstraint to a DataSet and sets the EnforceConstraints property to true.

Public Sub CreateDataTable()
    Dim dataTable As New DataTable()
    dataTable.Columns.Add("CustomerID", Type.GetType("System.String"))
    dataTable.Columns.Add("CompanyName", Type.GetType("System.String"))

    Dim uniqueConstraint As UniqueConstraint = _
      New UniqueConstraint("CustConstraint", _
      New DataColumn() {dataTable.Columns("CustomerID"), _
      dataTable.Columns("CompanyName")})

    dataTable.Constraints.Add(uniqueConstraint)
End Sub

注解

UniqueConstraint对单个列 (或列) 强制实施, 以确保主键值是唯一的。The UniqueConstraint is enforced on a single column (or columns) to ensure that a primary key value is unique.

除非将EnforceConstraints属性设置为true, 否则不会强制实施约束。Constraints are not enforced unless the EnforceConstraints property is set to true.

当与第二个DataSet合并时, 将不强制执行约束, 直到完成所有合并。 DataSetWhen the a DataSet is merged with a second DataSet, constraints are not enforced until all merges are completed.

构造函数

UniqueConstraint(DataColumn) UniqueConstraint(DataColumn) UniqueConstraint(DataColumn) UniqueConstraint(DataColumn)

使用指定的 UniqueConstraint 初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the specified DataColumn.

UniqueConstraint(DataColumn, Boolean) UniqueConstraint(DataColumn, Boolean) UniqueConstraint(DataColumn, Boolean) UniqueConstraint(DataColumn, Boolean)

用要约束的 UniqueConstraint 和指定约束是否为主键的值,初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the DataColumn to constrain, and a value specifying whether the constraint is a primary key.

UniqueConstraint(DataColumn[]) UniqueConstraint(DataColumn[]) UniqueConstraint(DataColumn[]) UniqueConstraint(DataColumn[])

用给定的 UniqueConstraint 对象的数组初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the given array of DataColumn objects.

UniqueConstraint(DataColumn[], Boolean) UniqueConstraint(DataColumn[], Boolean) UniqueConstraint(DataColumn[], Boolean) UniqueConstraint(DataColumn[], Boolean)

用要约束的 UniqueConstraint 对象的数组和指定约束是否为主键的值,初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with an array of DataColumn objects to constrain, and a value specifying whether the constraint is a primary key.

UniqueConstraint(String, DataColumn) UniqueConstraint(String, DataColumn) UniqueConstraint(String, DataColumn) UniqueConstraint(String, DataColumn)

使用指定的名称和 UniqueConstraint 初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the specified name and DataColumn.

UniqueConstraint(String, DataColumn, Boolean) UniqueConstraint(String, DataColumn, Boolean) UniqueConstraint(String, DataColumn, Boolean) UniqueConstraint(String, DataColumn, Boolean)

用指定名称、要约束的 UniqueConstraint 和指定约束是否为主键的值,初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the specified name, the DataColumn to constrain, and a value specifying whether the constraint is a primary key.

UniqueConstraint(String, DataColumn[]) UniqueConstraint(String, DataColumn[]) UniqueConstraint(String, DataColumn[]) UniqueConstraint(String, DataColumn[])

用指定的名称和 UniqueConstraint 对象的数组初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the specified name and array of DataColumn objects.

UniqueConstraint(String, DataColumn[], Boolean) UniqueConstraint(String, DataColumn[], Boolean) UniqueConstraint(String, DataColumn[], Boolean) UniqueConstraint(String, DataColumn[], Boolean)

用指定名称、要约束的 UniqueConstraint 对象的数组和指定约束是否为主键的值,初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the specified name, an array of DataColumn objects to constrain, and a value specifying whether the constraint is a primary key.

UniqueConstraint(String, String[], Boolean) UniqueConstraint(String, String[], Boolean) UniqueConstraint(String, String[], Boolean) UniqueConstraint(String, String[], Boolean)

用指定名称、要约束的 UniqueConstraint 对象的数组和指定约束是否为主键的值,初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the specified name, an array of DataColumn objects to constrain, and a value specifying whether the constraint is a primary key.

属性

Columns Columns Columns Columns

获取此约束影响的列的数组。Gets the array of columns that this constraint affects.

ConstraintName ConstraintName ConstraintName ConstraintName

ConstraintCollection 中的约束的名称。The name of a constraint in the ConstraintCollection.

(Inherited from Constraint)
ExtendedProperties ExtendedProperties ExtendedProperties ExtendedProperties

获取用户定义的约束属性的集合。Gets the collection of user-defined constraint properties.

(Inherited from Constraint)
IsPrimaryKey IsPrimaryKey IsPrimaryKey IsPrimaryKey

获取一个值,该值指示约束是否在主键上。Gets a value indicating whether or not the constraint is on a primary key.

Table Table Table Table

获取此约束所属的表。Gets the table to which this constraint belongs.

_DataSet _DataSet _DataSet _DataSet

获取此约束所属的 DataSetGets the DataSet to which this constraint belongs.

(Inherited from Constraint)

方法

CheckStateForProperty() CheckStateForProperty() CheckStateForProperty() CheckStateForProperty()

获取此约束所属的 DataSetGets the DataSet to which this constraint belongs.

(Inherited from Constraint)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

将此约束与第二个约束比较以确定两个约束是否相同。Compares this constraint to a second to determine if both are identical.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

获取 UniqueConstraint 对象的此实例的哈希代码。Gets the hash code of this instance of the UniqueConstraint object.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
SetDataSet(DataSet) SetDataSet(DataSet) SetDataSet(DataSet) SetDataSet(DataSet)

设置约束的 DataSetSets the constraint's DataSet.

(Inherited from Constraint)
ToString() ToString() ToString() ToString()

获取 ConstraintName(如果存在)作为字符串。Gets the ConstraintName, if there is one, as a string.

(Inherited from Constraint)

适用于

线程安全性

此类型适用于多线程读取操作。This type is suitable for multithreaded read operations. 必须同步任何写入操作。You must synchronize any write operations.

另请参阅