EntityTypeBuilder<TEntity>.HasAlternateKey Method

Definition

Overloads

HasAlternateKey(Expression<Func<TEntity,Object>>)

Creates an alternate key in the model for this entity type if one does not already exist over the specified properties. This will force the properties to be read-only. Use HasIndex(String[]) or HasIndex(Expression<Func<TEntity,Object>>) to specify uniqueness in the model that does not force properties to be read-only.

HasAlternateKey(String[])

Creates an alternate key in the model for this entity type if one does not already exist over the specified properties. This will force the properties to be read-only. Use HasIndex(String[]) or HasIndex(Expression<Func<TEntity,Object>>) to specify uniqueness in the model that does not force properties to be read-only.

HasAlternateKey(Expression<Func<TEntity,Object>>)

Creates an alternate key in the model for this entity type if one does not already exist over the specified properties. This will force the properties to be read-only. Use HasIndex(String[]) or HasIndex(Expression<Func<TEntity,Object>>) to specify uniqueness in the model that does not force properties to be read-only.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder HasAlternateKey (System.Linq.Expressions.Expression<Func<TEntity,object>> keyExpression);
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder<TEntity> HasAlternateKey (System.Linq.Expressions.Expression<Func<TEntity,object>> keyExpression);
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder<TEntity> HasAlternateKey (System.Linq.Expressions.Expression<Func<TEntity,object?>> keyExpression);
override this.HasAlternateKey : System.Linq.Expressions.Expression<Func<'Entity, obj>> -> Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder
override this.HasAlternateKey : System.Linq.Expressions.Expression<Func<'Entity, obj>> -> Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder<'Entity (requires 'Entity : null)>
Public Overridable Function HasAlternateKey (keyExpression As Expression(Of Func(Of TEntity, Object))) As KeyBuilder
Public Overridable Function HasAlternateKey (keyExpression As Expression(Of Func(Of TEntity, Object))) As KeyBuilder(Of TEntity)

Parameters

keyExpression
Expression<Func<TEntity,Object>>

A lambda expression representing the key property(s) (blog => blog.Url).

If the key is made up of multiple properties then specify an anonymous type including the properties (post => new { post.Title, post.BlogId }).

Returns

KeyBuilder<TEntity>

An object that can be used to configure the key.

Applies to

HasAlternateKey(String[])

Creates an alternate key in the model for this entity type if one does not already exist over the specified properties. This will force the properties to be read-only. Use HasIndex(String[]) or HasIndex(Expression<Func<TEntity,Object>>) to specify uniqueness in the model that does not force properties to be read-only.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder<TEntity> HasAlternateKey (params string[] propertyNames);
override this.HasAlternateKey : string[] -> Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder<'Entity (requires 'Entity : null)>
Public Overridable Function HasAlternateKey (ParamArray propertyNames As String()) As KeyBuilder(Of TEntity)

Parameters

propertyNames
String[]

The names of the properties that make up the key.

Returns

KeyBuilder<TEntity>

An object that can be used to configure the key.

Applies to