Help translating "CREATE INDEX" to Data Annotations

Stesvis 1,041 Reputation points
2022-09-18T03:50:58.74+00:00

Hello everybody,

How can I translate something like this

   CREATE INDEX [missing_index_10_9_WATravelUsers] ON [WATravelUsers] ([UserId]) INCLUDE ([TravelId]) WITH(FILLFACTOR=70)  

into data annotations in EF6?
Thanks!

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,342 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,243 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 54,866 Reputation points
    2022-09-18T15:30:18.897+00:00

  2. Lan Huang-MSFT 25,386 Reputation points Microsoft Vendor
    2022-09-19T05:14:51.717+00:00

    Hi @Stesvis ,
    You can check out the documentation below:
    https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/data-annotations
    This article will focus on using DataAnnotations (in the System.ComponentModel.DataAnnotations namespace) to configure your classes.

    You can create an index on one or more columns using the IndexAttribute. Adding the attribute to one or more properties will cause EF to create the corresponding index in the database when it creates the database, or scaffold the corresponding CreateIndex calls if you are using Code First Migrations.

    Note:EF6.1 Onwards Only
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments