ColumnAttribute.IsPrimaryKey 속성

정의

이 클래스 멤버가 테이블의 기본 키의 일부인 열을 나타내는지 여부를 가져오거나 설정합니다.

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

속성 값

기본값 = false.

예제

[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

설명

엔터티 클래스를 가정할 때 이 특성을 가진 멤버를 하나 이상 제공해야 하며, 해당 테이블 또는 뷰의 기본 키 또는 고유 키에 매핑되어야 합니다. 이렇게 하지 않으면 LINQ to SQL에서 데이터베이스에 변경 내용을 제출하기 위한 읽기 전용으로 클래스의 인스턴스를 고려하라는 메시지가 표시됩니다.

이 속성을 사용하여 둘 이상의 클래스 멤버를 지정하는 경우 키는 연결된 열의 복합이라고 합니다.

메모

LINQ to SQL은 계산 열을 기본 키로 지원하지 않습니다.

적용 대상