ColumnAttribute.IsPrimaryKey ColumnAttribute.IsPrimaryKey ColumnAttribute.IsPrimaryKey ColumnAttribute.IsPrimaryKey Property

Definition

Gets or sets whether this class member represents a column that is part or all of the primary key of the table.

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

Property Value

Default = false.

Examples

[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

Remarks

Assuming an entity class, you must provide at least one member with this attribute, and it must be mapped to the primary key or a unique key in the corresponding table or view. Failure to do this prompts LINQ to SQL to consider instances of the class as read-only for submitting changes to the database.

If you designate more than one member of the class by using this property, the key is said to be a composite of the associated columns.

Note

LINQ to SQL does not support computed columns as primary keys.

Applies to