ColumnAttribute.IsPrimaryKey Propriedade

Definição

Obtém ou define se esse membro de classe representa uma coluna que faz parte ou toda a 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 da 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

Comentários

Supondo que uma classe de entidade, você deve fornecer pelo menos um membro com esse atributo e ele deve ser mapeado para a chave primária ou uma chave exclusiva na tabela ou exibição correspondente. A falha ao fazer isso solicita que o LINQ to SQL considere instâncias da classe como somente leitura para enviar alterações ao banco de dados.

Se você designar mais de um membro da classe usando essa propriedade, a chave será considerada uma composição das colunas associadas.

Note

O LINQ to SQL não dá suporte a colunas computadas como chaves primárias.

Aplica-se a