How to create a Clustered Index with Entity Framework Core

前端 未结 4 624
广开言路
广开言路 2020-12-10 12:53

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 U         


        
4条回答
  •  半阙折子戏
    2020-12-10 13:23

    From the current EF Core documentation - Indexes section:

    Data Annotations

    Indexes can not be created using data annotations.

    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()
        .HasIndex(e => e.UserName)
        .IsUnique()
        .ForSqlServerIsClustered();
    

提交回复
热议问题