TableBuilder<TColumns>.PrimaryKey Method (Expression<Func<TColumns, Object>>, String, Boolean, Object)

 

Specifies a primary key for the table. Entity Framework Migrations APIs are not designed to accept input provided by untrusted sources (such as the end user of an application). If input is accepted from such sources it should be validated before being passed to these APIs to protect against SQL injection attacks etc.

Namespace:   System.Data.Entity.Migrations.Builders
Assembly:  EntityFramework (in EntityFramework.dll)

[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public TableBuilder<TColumns> PrimaryKey(
	Expression<Func<TColumns, object>> keyExpression,
	string name = null,
	bool clustered = true,
	object anonymousArguments = null
)

Parameters

keyExpression
Type: System.Linq.Expressions.Expression<Func<TColumns, Object>>

A lambda expression representing the property to be used as the primary key. C#: t =&gt; t.Id VB.Net: Function(t) t.Id If the primary key is made up of multiple properties then specify an anonymous type including the properties. C#: t =&gt; new { t.Id1, t.Id2 } VB.Net: Function(t) New With { t.Id1, t.Id2 }

name
Type: System.String

The name of the primary key. If null is supplied, a default name will be generated.

clustered
Type: System.Boolean

A value indicating whether or not this is a clustered primary key.

anonymousArguments
Type: System.Object

Additional arguments that may be processed by providers. Use anonymous type syntax to specify arguments e.g. 'new { SampleArgument = "MyValue" }'.

Return Value

Type: System.Data.Entity.Migrations.Builders.TableBuilder<TColumns>

Itself, so that multiple calls can be chained.