This topic has not yet been rated - Rate this topic

ColumnAttribute.IsPrimaryKey Property

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

Namespace:  System.Data.Linq.Mapping
Assembly:  System.Data.Linq (in System.Data.Linq.dll)
public bool IsPrimaryKey { get; set; }

Property Value

Type: System.Boolean
Default = false.

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 Note

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


	[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();
			}
		}
	}


.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ