Rule Enumeração
Definição
Indica a ação que ocorre quando um ForeignKeyConstraint é imposto.Indicates the action that occurs when a ForeignKeyConstraint is enforced.
public enum class Rule
public enum Rule
type Rule =
Public Enum Rule
- Herança
Campos
Cascade | 1 | Excluir ou atualizar linhas relacionadas.Delete or update related rows. Esse é o padrão.This is the default. |
None | 0 | Nenhuma ação em linhas relacionadas.No action taken on related rows. |
SetDefault | 3 | Definir valores em linhas relacionadas como o valor contido na propriedade DefaultValue.Set values in related rows to the value contained in the DefaultValue property. |
SetNull | 2 | Definir valores em linhas relacionadas como |
Exemplos
' The next line goes into the Declarations section of the module:
' SuppliersProducts is a class derived from DataSet.
Private suppliersProducts As SuppliersProducts
Private Sub CreateConstraint()
' Declare parent column and child column variables.
Dim parentColumn As DataColumn
Dim childColumn As DataColumn
Dim fkeyConstraint As ForeignKeyConstraint
' Set parent and child column variables.
parentColumn = suppliersProducts.Tables("Suppliers").Columns("SupplierID")
childColumn = suppliersProducts.Tables("Products").Columns("SupplierID")
fkeyConstraint = New ForeignKeyConstraint( _
"SupplierFKConstraint", parentColumn, childColumn)
' Set null values when a value is deleted.
fkeyConstraint.DeleteRule = Rule.SetNull
fkeyConstraint.UpdateRule = Rule.Cascade
fkeyConstraint.AcceptRejectRule = AcceptRejectRule.Cascade
' Add the constraint, and set EnforceConstraints to true.
suppliersProducts.Tables("Products").Constraints.Add(fkeyConstraint)
suppliersProducts.EnforceConstraints = True
End Sub
Comentários
Os Rule valores são definidos como o UpdateRule e as DeleteRule propriedades ForeignKeyConstraint deumDataTable objeto encontrado em um objeto. ConstraintCollectionThe Rule values are set to the UpdateRule and the DeleteRule properties of a ForeignKeyConstraint object found in a DataTable object's ConstraintCollection.
Os Rule valores determinam a ação que ocorre quando um valor em uma coluna é excluído ou atualizado.The Rule values determine the action that occurs when a value in a column is either deleted or updated. Dos dois, excluir um valor é o mais crítico e exige atenção ao definir uma regra.Of the two, deleting a value is the more critical and demanding of attention when setting a rule.
No caso em que um valor é excluído, Cascade
especifica que todas as linhas que contêm esse valor também são excluídas.In the case where a value is deleted, Cascade
specifies that all rows containing that value are also deleted. SetNull
Especifica que os valores em todas as colunas filho são definidos como valores nulos.SetNull
specifies that values in all child columns are set to null values. SetDefault
Especifica que todas as colunas filho sejam definidas como o valor padrão para a coluna.SetDefault
specifies that all child columns be set to the default value for the column. None
Especifica que nenhuma ação ocorrerá, mas exceções são geradas.None
specifies that no action will occur, but exceptions are generated.
No caso em que um valor é atualizado, Cascade
especifica que todas as colunas filho são atualizadas da mesma forma com o novo valor.In the case where a value is updated, Cascade
specifies that all child columns are likewise updated with the new value. SetNull
Especifica que todas as colunas filho sejam definidas como valores nulos.SetNull
specifies that all child columns be set to null values. SetDefault
Especifica que todos os valores de coluna filho sejam definidos como o valor padrão.SetDefault
specifies that all child column values be set to the default value. None
Especifica que nenhuma ação seja executada, mas exceções são geradas.None
specifies that no action be taken, but exceptions are generated.
As restrições em DataSet um não são impostas, EnforceConstraints a menos true
que a propriedade seja.Constraints on a DataSet are not enforced unless the EnforceConstraints property is true
.
Quando o AcceptChanges método é chamado, o AcceptRejectRule mais determina o que a ação ocorre.When the AcceptChanges method is called, the AcceptRejectRule further determines what action occurs.