[Index(nameof(Url))] public class Blog { public int BlogId { get; set; } public string Url { get; set; } }
Composite index
[Index(nameof(FirstName), nameof(LastName))] public class Person { public int PersonId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } }
Index uniqueness
[Index(nameof(Url), IsUnique = true)] public class Blog { public int BlogId { get; set; } public string Url { get; set; } }
Index sort order
[Index(nameof(Url), nameof(Rating), AllDescending = true)] public class Blog { public int BlogId { get; set; } public string Url { get; set; } public int Rating { get; set; } }
[Index(nameof(Url), nameof(Rating), IsDescending = new[] { false, true })] public class Blog { public int BlogId { get; set; } public string Url { get; set; } public int Rating { get; set; } }
Index name
[Index(nameof(Url), Name = "Index_Url")] public class Blog { public int BlogId { get; set; } public string Url { get; set; } }
References
https://learn.microsoft.com/en-us/ef/core/modeling/indexes?tabs=data-annotations