Steven Lemmens
Steven Lemmens

Reputation: 1491

Entity Framework 6 migrations : create index with include columns code first

I'm looking for a way to create an index like this with Entity Framework 6.1:

 CREATE INDEX [IX_MYINDEX] ON [db].[dbo].[Payments] ([IsDeleted])
 INCLUDE ([Id], [InvoiceId], [OrderId])

I've found several other answers saying it can't be done because of the "Include" columns, but all of those answers are from 3 years ago so I wonder if something has been added that would make this into a possibility.

We'd like to avoid (if at all possible) to have real SQL in our code and prefer a real code-first solution where we annotate the Model-classes. I've tried Googling for it and I've spent some time reading different answers on Stackoverflow but can't seem to find the right fit. Can anyone point me in the right direction please?

Thank you very much

Upvotes: 7

Views: 2517

Answers (2)

ErikEJ
ErikEJ

Reputation: 41759

No, still not possible in EF6 and EF Core

Upvotes: 4

Georg Patscheider
Georg Patscheider

Reputation: 9463

Not sure if this can be done with data annotations, but you can create an EF migration:

CreateIndex("dbo.Payments", new[] {"IsDeleted", "Id", "InvoiceId", "OrderId"}, name: "IX_MYINDEX");

Upvotes: -1

Related Questions