7

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

2
  • I have exactly the same question and preference (have data annotations populate all SQL) and was wondering if there is an update (2018) Because I could not find it in any docs (yet). Commented Jan 26, 2018 at 10:14
  • I also have the same question. It is now April 2019. I'm using EF6 and EF Core (different projects). Commented Apr 10, 2019 at 7:16

2 Answers 2

4

No, still not possible in EF6 and EF Core

Sign up to request clarification or add additional context in comments.

Comments

-1

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");

2 Comments

Well, this is just a multi column index which can be created with annotations. OP is asking for index on IsDeleted column including (but not indexing) some other columns, which is different.
OK, I misunderstood the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.