Can EF7 Create non-clustered primary key?

entity-framework-core

Question

In EF6.1 we had to use migration to get a non-clustered PK. Does anyone know if EF7 have first-class support for non-clustered PK or do we have to use work arounds again?

1
0
2/22/2016 8:37:19 PM

Accepted Answer

You might have your answer now, since EF Core 1.0 (formerly EF7) is baked. But just in case you didn't know or if any one else comes across this thread...

EF Core does have support within the mssql provider.

https://github.com/aspnet/EntityFramework/issues/5790

1
7/7/2016 3:20:19 PM

Popular Answer

You can do it in Entity Framework Core Code First by ovveriding OnModelCreating in DbContext

  p.HasKey(b => b.ColumnId).ForSqlServerIsClustered(false);

This will generate migration like this:

 table.PrimaryKey("PK_Columns", x => x.ColumnId)
                        .Annotation("SqlServer:Clustered", false);


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow