OwnedNavigationBuilder<TOwnerEntity,TDependentEntity>.HasKey 方法

定义

重载

HasKey(Expression<Func<TDependentEntity,Object>>)

设置构成此自有实体类型的主键的属性。

HasKey(String[])

设置构成此自有实体类型的主键的属性。

HasKey(Expression<Func<TDependentEntity,Object>>)

设置构成此自有实体类型的主键的属性。

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

参数

keyExpression
Expression<Func<TDependentEntity,Object>>

表示主键属性的 lambda 表达式, () (blog => blog.Url) 。

如果主键由多个属性组成,则指定一个匿名类型,包括 (post => new { post.Title, post.BlogId }) 的属性。

返回

KeyBuilder<TDependentEntity>

可用于配置主键的 对象。

适用于

HasKey(String[])

设置构成此自有实体类型的主键的属性。

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

参数

propertyNames
String[]

构成主键的属性的名称。

返回

KeyBuilder<TDependentEntity>

可用于配置主键的 对象。

适用于