ColumnAttribute.IsPrimaryKey Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta un valore che indica se questo membro della classe rappresenta una colonna che fa parte o tutta la chiave primaria della tabella.
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
Valore della proprietà
Valore predefinito = false.
Esempio
[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
Commenti
Supponendo che una classe di entità, è necessario fornire almeno un membro con questo attributo e deve essere mappato alla chiave primaria o a una chiave univoca nella tabella o nella vista corrispondente. Se non si esegue questa operazione, LINQ to SQL viene richiesto di considerare le istanze della classe come di sola lettura per l'invio di modifiche al database.
Se si designano più membri della classe usando questa proprietà, la chiave viene definita come composta delle colonne associate.
Note
LINQ to SQL non supporta le colonne calcolate come chiavi primarie.