Sugerir traducción
 
Otros han sugerido:

progress indicator
No hay más sugerencias.
Evaluar y enviar comentarios
Contraer todo/Expandir todo Contraer todo
Ver contenido:  en paraleloVer contenido: en paralelo
.NET Framework Class Library
ForeignKeyConstraint Class

Represents an action restriction enforced on a set of columns in a primary key/foreign key relationship when a value or row is either deleted or updated.

System..::.Object
  System.Data..::.Constraint
    System.Data..::.ForeignKeyConstraint

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)
Visual Basic
Public Class ForeignKeyConstraint _
    Inherits Constraint
C#
public class ForeignKeyConstraint : Constraint
Visual C++
public ref class ForeignKeyConstraint : public Constraint
F#
type ForeignKeyConstraint =  
    class
        inherit Constraint
    end

The ForeignKeyConstraint type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkForeignKeyConstraint(DataColumn, DataColumn)Initializes a new instance of the ForeignKeyConstraint class with the specified parent and child DataColumn objects.
Public methodSupported by the XNA FrameworkForeignKeyConstraint(array<DataColumn>[]()[], array<DataColumn>[]()[])Initializes a new instance of the ForeignKeyConstraint class with the specified arrays of parent and child DataColumn objects.
Public methodSupported by the XNA FrameworkForeignKeyConstraint(String, DataColumn, DataColumn)Initializes a new instance of the ForeignKeyConstraint class with the specified name, parent and child DataColumn objects.
Public methodSupported by the XNA FrameworkForeignKeyConstraint(String, array<DataColumn>[]()[], array<DataColumn>[]()[])Initializes a new instance of the ForeignKeyConstraint class with the specified name, and arrays of parent and child DataColumn objects.
Public methodSupported by the XNA FrameworkForeignKeyConstraint(String, String, array<String>[]()[], array<String>[]()[], AcceptRejectRule, Rule, Rule)This constructor is provided for design time support in the Visual Studio environment. ForeignKeyConstraint objects created by using this constructor must then be added to the collection via AddRange. Tables and columns with the specified names must exist at the time the method is called, or if BeginInit has been called prior to calling this constructor, the tables and columns with the specified names must exist at the time that EndInit is called.
Public methodSupported by the XNA FrameworkForeignKeyConstraint(String, String, String, array<String>[]()[], array<String>[]()[], AcceptRejectRule, Rule, Rule)This constructor is provided for design time support in the Visual Studio environment. ForeignKeyConstraint objects created by using this constructor must then be added to the collection via AddRange. Tables and columns with the specified names must exist at the time the method is called, or if BeginInit has been called prior to calling this constructor, the tables and columns with the specified names must exist at the time that EndInit is called.
Top
  NameDescription
Protected propertySupported by the XNA Framework_DataSetInfrastructure. Gets the DataSet to which this constraint belongs. (Inherited from Constraint.)
Public propertySupported by the XNA FrameworkAcceptRejectRuleIndicates the action that should take place across this constraint when AcceptChanges is invoked.
Public propertySupported by the XNA FrameworkColumnsGets the child columns of this constraint.
Public propertySupported by the XNA FrameworkConstraintNameThe name of a constraint in the ConstraintCollection. (Inherited from Constraint.)
Public propertySupported by the XNA FrameworkDeleteRuleGets or sets the action that occurs across this constraint when a row is deleted.
Public propertySupported by the XNA FrameworkExtendedPropertiesGets the collection of user-defined constraint properties. (Inherited from Constraint.)
Public propertySupported by the XNA FrameworkRelatedColumnsThe parent columns of this constraint.
Public propertySupported by the XNA FrameworkRelatedTableGets the parent table of this constraint.
Public propertySupported by the XNA FrameworkTableGets the child table of this constraint. (Overrides Constraint..::.Table.)
Public propertySupported by the XNA FrameworkUpdateRuleGets or sets the action that occurs across this constraint on when a row is updated.
Top
  NameDescription
Protected methodSupported by the XNA FrameworkCheckStateForPropertyInfrastructure. Gets the DataSet to which this constraint belongs. (Inherited from Constraint.)
Public methodSupported by the XNA FrameworkEqualsGets a value indicating whether the current ForeignKeyConstraint is identical to the specified object. (Overrides Object..::.Equals(Object).)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetHashCodeGets the hash code of this instance of the ForeignKeyConstraint object. (Overrides Object..::.GetHashCode()()().)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkSetDataSetSets the constraint's DataSet. (Inherited from Constraint.)
Public methodSupported by the XNA FrameworkToStringGets the ConstraintName, if there is one, as a string. (Inherited from Constraint.)
Top

A ForeignKeyConstraint restricts the action performed when a value in a column (or columns) is either deleted or updated. Such a constraint is intended to be used with primary key columns. In a parent/child relationship between two tables, deleting a value from the parent table can affect the child rows in one of the following ways.

  • The child rows can also be deleted (a cascading action).

  • The values in the child column (or columns) can be set to null values.

  • The values in the child column (or columns) can be set to default values.

  • An exception can be generated.

ForeignKeyConstraint objects are contained in the ConstraintCollection of a DataTable, which is accessed through the Constraints property.

Constraints are not enforced unless the EnforceConstraints property is set to true.

The AcceptRejectRule is enforced whenever a DataTable object's AcceptChanges method is invoked.

The following example creates a ForeignKeyConstraint, sets some of its properties, and adds it to a DataTable object's ConstraintCollection.

Visual Basic
' 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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

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.

Biblioteca de clases de .NET Framework
ForeignKeyConstraint (Clase)

Representa la restricción de una acción impuesta a un conjunto de columnas en una relación entre clave principal y clave externa cuando se elimina o actualiza un valor o una fila.

System..::.Object
  System.Data..::.Constraint
    System.Data..::.ForeignKeyConstraint

Espacio de nombres:  System.Data
Ensamblado:  System.Data (en System.Data.dll)
Visual Basic
Public Class ForeignKeyConstraint _
    Inherits Constraint
C#
public class ForeignKeyConstraint : Constraint
Visual C++
public ref class ForeignKeyConstraint : public Constraint
F#
type ForeignKeyConstraint =  
    class
        inherit Constraint
    end

El tipo ForeignKeyConstraint expone los siguientes miembros.

  NombreDescripción
Método públicoCompatible con XNA FrameworkForeignKeyConstraint(DataColumn, DataColumn)Inicializa una nueva instancia de la clase ForeignKeyConstraint con los objetos DataColumn primarios y secundarios especificados.
Método públicoCompatible con XNA FrameworkForeignKeyConstraint(array<DataColumn>[]()[], array<DataColumn>[]()[])Inicializa una nueva instancia de la clase ForeignKeyConstraint con las matrices especificadas de objetos DataColumn primarios y secundarios.
Método públicoCompatible con XNA FrameworkForeignKeyConstraint(String, DataColumn, DataColumn)Inicializa una nueva instancia de la clase ForeignKeyConstraint con el nombre especificado para los objetos DataColumn primarios y secundarios.
Método públicoCompatible con XNA FrameworkForeignKeyConstraint(String, array<DataColumn>[]()[], array<DataColumn>[]()[])Inicializa una nueva instancia de la clase ForeignKeyConstraint con el nombre y matrices especificados de objetos DataColumn primarios y secundarios.
Método públicoCompatible con XNA FrameworkForeignKeyConstraint(String, String, array<String>[]()[], array<String>[]()[], AcceptRejectRule, Rule, Rule)Este constructor proporciona compatibilidad en tiempo de diseño en el entorno de Visual Studio. Los objetos ForeignKeyConstraint que se creen utilizando este constructor deben agregarse a la colección mediante AddRange. Deben existir tablas o columnas con los nombres especificados en el momento de llamar al método, o bien si se ha llamado a BeginInit antes de llamar a este constructor, deben existir tablas o columnas con los nombres especificados en el momento de llamar a EndInit.
Método públicoCompatible con XNA FrameworkForeignKeyConstraint(String, String, String, array<String>[]()[], array<String>[]()[], AcceptRejectRule, Rule, Rule)Este constructor proporciona compatibilidad en tiempo de diseño en el entorno de Visual Studio. Los objetos ForeignKeyConstraint que se creen utilizando este constructor deben agregarse a la colección mediante AddRange. Deben existir tablas o columnas con los nombres especificados en el momento de llamar al método, o bien si se ha llamado a BeginInit antes de llamar a este constructor, deben existir tablas o columnas con los nombres especificados en el momento de llamar a EndInit.
Arriba
  NombreDescripción
Propiedad protegidaCompatible con XNA Framework_DataSetInfraestructura. Obtiene el objeto DataSet al que pertenece esta restricción. (Se hereda de Constraint).
Propiedad públicaCompatible con XNA FrameworkAcceptRejectRuleIndica la acción que se debe llevar a cabo en esta restricción cuando se llama a AcceptChanges.
Propiedad públicaCompatible con XNA FrameworkColumnsObtiene las columnas secundarias de esta restricción.
Propiedad públicaCompatible con XNA FrameworkConstraintNameNombre de una restricción en el ConstraintCollection. (Se hereda de Constraint).
Propiedad públicaCompatible con XNA FrameworkDeleteRuleObtiene o establece la acción que se produce en esta restricción cuando se elimina una fila.
Propiedad públicaCompatible con XNA FrameworkExtendedPropertiesObtiene la colección de propiedades de restricción definidas por el usuario. (Se hereda de Constraint).
Propiedad públicaCompatible con XNA FrameworkRelatedColumnsColumnas primarias de esta restricción.
Propiedad públicaCompatible con XNA FrameworkRelatedTableObtiene la tabla primaria de esta restricción.
Propiedad públicaCompatible con XNA FrameworkTableObtiene la tabla secundaria de esta restricción. (Invalida a Constraint..::.Table).
Propiedad públicaCompatible con XNA FrameworkUpdateRuleObtiene o establece la acción que se produce en esta restricción cuando se actualiza una fila.
Arriba
  NombreDescripción
Método protegidoCompatible con XNA FrameworkCheckStateForPropertyInfraestructura. Obtiene el objeto DataSet al que pertenece esta restricción. (Se hereda de Constraint).
Método públicoCompatible con XNA FrameworkEqualsObtiene un valor que indica si el ForeignKeyConstraint actual es idéntico al objeto especificado. (Invalida a Object..::.Equals(Object)).
Método protegidoCompatible con XNA FrameworkFinalizePermite que un objeto intente liberar recursos y realizar otras operaciones de limpieza antes de ser reclamado por la recolección de elementos no utilizados. (Se hereda de Object).
Método públicoCompatible con XNA FrameworkGetHashCodeObtiene el código hash de esta instancia del objeto ForeignKeyConstraint. (Invalida a Object..::.GetHashCode()()()).
Método públicoCompatible con XNA FrameworkGetTypeObtiene el objeto Type de la instancia actual. (Se hereda de Object).
Método protegidoCompatible con XNA FrameworkMemberwiseCloneCrea una copia superficial del objeto Object actual. (Se hereda de Object).
Método protegidoCompatible con XNA FrameworkSetDataSetEstablece el objeto DataSet de la restricción. (Se hereda de Constraint).
Método públicoCompatible con XNA FrameworkToStringObtiene el ConstraintName, si existe, como una cadena. (Se hereda de Constraint).
Arriba

ForeignKeyConstraint restringe la acción realizada cuando se elimina o actualiza un valor de columnas. Este tipo de restricción está pensado para utilizarlo con columnas de clave principal. En una relación primaria-secundaria entre dos tablas, la eliminación de un valor de la tabla primaria puede afectar las filas secundarias de una de las formas siguientes.

  • También se pueden eliminar las filas secundarias (acción en cascada).

  • Los valores de las columnas secundarias se pueden establecen en nulos.

  • Los valores de las columnas secundarias se pueden establecer en predeterminados.

  • Se puede generar una excepción.

Los objetos ForeignKeyConstraint están incluidos en el ConstraintCollection de un DataTable, al que se obtiene acceso mediante la propiedad Constraints.

Las restricciones no se fuerzan a menos que la propiedad EnforceConstraints esté establecida en true.

AcceptRejectRule se fuerza siempre que se invoca el método AcceptChanges de un objeto DataTable.

En el ejemplo siguiente se crea un ForeignKeyConstraint, se establecen algunas de sus propiedades y se agrega a un ConstraintCollection de un objeto DataTable.

Visual Basic
' 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

.NET Framework

Compatible con: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Compatible con: 4, 3.5 SP1

Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2

.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Este tipo es seguro para operaciones de lectura multiproceso. Debe sincronizar cualquier operación de escritura.

Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2012 Microsoft. Reservados todos los derechos. Términos de uso | Marcas Registradas | Privacidad
Page view tracker