4

I would like to define an index in the EF modelbuilder which has an included column.

I can add columns which are part of the index like this (Via the index annotation):

base.Property(x => x.Col1).HasColumnAnnotation(
    IndexAnnotation.AnnotationName,
        new IndexAnnotation(
            new IndexAttribute("IX_MyIndex", 1) { IsUnique = false, IsClustered = false }));

base.Property(x => x.Col2).HasColumnAnnotation(
    IndexAnnotation.AnnotationName,
        new IndexAnnotation(
            new IndexAttribute("IX_MyIndex", 2) { IsUnique = false, IsClustered = false }));

but I want to generate something like the following:

CREATE NONCLUSTERED INDEX [MyIndex] ON [MyTable]
(
    [Col1] ASC
)
INCLUDE ([Col2])
undefined
  • 33,537
  • 22
  • 129
  • 198
  • Possible answer: http://stackoverflow.com/questions/22618237/how-to-create-index-in-entity-framework-6-2-with-code-first – Murilo Jan 12 '17 at 17:21

0 Answers0