ColumnAttribute.IsPrimaryKey Propriedade

Definição

Obtém ou define se este membro da classe representa uma coluna que faz parte ou a totalidade da chave primária da tabela.

public:
 property bool IsPrimaryKey { bool get(); void set(bool value); };
public bool IsPrimaryKey { get; set; }
member this.IsPrimaryKey : bool with get, set
Public Property IsPrimaryKey As Boolean

Valor de Propriedade

Padrão = false.

Exemplos

[Column(Storage="_ProductID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public int ProductID
{
    get
    {
        return this._ProductID;
    }
    set
    {
        if ((this._ProductID != value))
        {
            this.OnProductIDChanging(value);
            this.SendPropertyChanging();
            this._ProductID = value;
            this.SendPropertyChanged("ProductID");
            this.OnProductIDChanged();
        }
    }
}
<Column(Storage:="_ProductID", DbType:="Int NOT NULL", IsPrimaryKey:=true, IsDbGenerated:=true)>  _
Public Property ProductID() As Integer
    Get
        Return Me._ProductID
    End Get
    Set
        If ((Me._ProductID = value)  _
                    = false) Then
            If Me._Product.HasLoadedOrAssignedValue Then
                Throw New System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException
            End If
            Me.OnProductIDChanging(value)
            Me.SendPropertyChanging
            Me._ProductID = value
            Me.SendPropertyChanged("ProductID")
            Me.OnProductIDChanged
        End If
    End Set
End Property

Observações

Assumindo uma classe de entidade, deve fornecer pelo menos um membro com este atributo, e este deve ser mapeado para a chave primária ou para uma chave única na tabela ou vista correspondente. A falha em fazer isto leva o LINQ para SQL a considerar as instâncias da classe como apenas leitura para submeter alterações à base de dados.

Se designar mais do que um membro da classe usando esta propriedade, diz-se que a chave é uma composição das colunas associadas.

Note

LINQ para SQL não suporta colunas computadas como chaves primárias.

Aplica-se a