UniqueConstraint 类

定义

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

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

示例

下面的示例将 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 与第二个 DataSet合并时,在所有合并完成之前不会强制执行约束。When the a DataSet is merged with a second DataSet, constraints are not enforced until all merges are completed.

构造函数

UniqueConstraint(DataColumn)

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

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 类的新实例。Initializes a new instance of the UniqueConstraint class with the given array of DataColumn objects.

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 初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the specified name and DataColumn.

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 对象的数组初始化 DataColumn 类的新实例。Initializes a new instance of the UniqueConstraint class with the specified name and array of DataColumn objects.

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 对象的数组和指定约束是否为主键的值,初始化 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.

属性

_DataSet

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

(继承自 Constraint)
Columns

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

ConstraintName

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

(继承自 Constraint)
ExtendedProperties

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

(继承自 Constraint)
IsPrimaryKey

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

Table

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

方法

CheckStateForProperty()

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

(继承自 Constraint)
Equals(Object)

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

GetHashCode()

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

GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
SetDataSet(DataSet)

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

(继承自 Constraint)
ToString()

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

(继承自 Constraint)

适用于

线程安全性

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

另请参阅