EF 4.3 Code Migrations with CreateIndex and Anonymous Arguments

I am trying to create an index using EF Code Migrations. The index looks something like this:

CREATE INDEX [IX_RatingId_CreatedAt] ON [Users] 
(
[RatingId] ASC,
[CreatedAt] ASC
)
INCLUDE (Id, Email, DomainId)

The code I have so far is:

CreateIndex("Users",
             new string[] { "RatingId", "CreatedAt" },
             false,
             "IX_RatingId_CreatedAt"
           );

This will create an index for me, but it will not include columns. The CreateIndex method has an override that accepts something called anonymousArguments. I cannot find such information, so I tried something like:

CreateIndex("Users",
             new string[] { "RatingId", "CreatedAt" },
             false,
             "IX_RatingId_CreatedAt",
             new { INCLUDE = "(Id, Email, DomainId)" });

There were no exceptions, but it did not work.

Is it possible to create the above index using the CreateIndex method or do I need to use the Sql method to write T-SQL in my migration? How to use anonymous arguments correctly?

+5
source share
1 answer

. , MSSQL (, , ).

CreateIndex, . SQL, .

CreateIndex("Users",
         new string[] { "RatingId", "CreatedAt", "Id", "Email", "DomainId" },
         false,
         "IX_RatingId_CreatedAt"
       );
+7

All Articles