如何使用实体框架核心创建聚簇索引 [英] How to create a Clustered Index with Entity Framework Core
本文介绍了如何使用实体框架核心创建聚簇索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从EF6.1开始,我们可以在属性上指定聚簇索引
From EF6.1, we have a way of specifying a clustered index on a property
public class Person
{
[Index(IsClustered = true, IsUnique = true)]
public long UserName { get; set; }
}
但是这个Index属性现在似乎不在EF Core中吗?在EF Core中,您如何实现此目标?
But this Index attribute does not seem to be in EF Core right now? In EF Core how do you achieve this?
推荐答案
从当前EF Core文档中-索引部分:
From the current EF Core documentation - Indexes section:
数据注释
无法使用数据注释创建索引。
Indexes can not be created using data annotations.
但是可以肯定的是,您可以通过Fluent API进行指定(请注意,前缀为 ForSqlServer
的扩展方法似乎表示SqlServer的特定功能):
But for sure you can specify that via Fluent API (note the extension methods having ForSqlServer
prefix which seem to denote SqlServer specific features):
modelBuilder.Entity<Person>()
.HasIndex(e => e.UserName)
.IsUnique()
.ForSqlServerIsClustered();
这篇关于如何使用实体框架核心创建聚簇索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文