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
[<System.Serializable>]
type UniqueConstraint = class
inherit Constraint
Public Class UniqueConstraint
Inherits Constraint
- Наследование
- Атрибуты
Примеры
В следующем примере добавляется UniqueConstraint в DataSet и присваивается EnforceConstraints свойству значение true
.The 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 слиянии a с вторым 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 |
Возвращает объект DataSet, которому принадлежит данное ограничение.Gets 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() |
Возвращает объект DataSet, которому принадлежит данное ограничение.Gets 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() |
Возвращает объект Type для текущего экземпляра.Gets the Type of the current instance. (Унаследовано от Object) |
MemberwiseClone() |
Создает неполную копию текущего объекта Object.Creates a shallow copy of the current Object. (Унаследовано от Object) |
SetDataSet(DataSet) |
Задает объект DataSet ограничения.Sets 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.