You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you define multiple indexes for an entity over the same columns but with a different filter expression and/or name, EF will only create a migration statement for the last one.
Steps to reproduce
Create a project with this model:
publicclassState{publicGuidId{get;set;}publicDateTimeLastModified{get;set;}=DateTime.UtcNow;publicint?CustomerId{get;set;}publicint?ItemId{get;set;}publicint?ItemGroupId{get;set;}[Required,StringLength(450)]publicstringRemoteId{get;set;}}publicclassStateDbContext:DbContext{publicDbSet<State>State{get;set;}protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){modelBuilder.Entity<State>(s =>{s.HasIndex("RemoteId").HasFilter("CustomerId IS NOT NULL").HasName("IX_State_RemoteId_CustomerId").IsUnique();s.HasIndex("RemoteId").HasFilter("ItemId IS NOT NULL").HasName("IX_State_RemoteId_ItemId").IsUnique();s.HasIndex("RemoteId").HasFilter("ItemGroupId IS NOT NULL").HasName("IX_State_RemoteId_ItemGroupId").IsUnique();});}}
Notice that even though the index uses the same property RemoteId, the name and filter for each index is different (I can create such indexes on SQL server with T-SQL)
Add a migration: dotnet ef migrations add CreateInitialSchema
Notice that the generated migration only contains the index IX_State_RemoteId_ItemGroupId.
Further technical details
EF Core version: both 2.* and 3.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: netcoreapp2.2 / netcoreapp3.0
Operating system: Windows 10
IDE: N/A
The text was updated successfully, but these errors were encountered:
cornem
changed the title
Migration should create indexes for same columns but different filters
AddMigration doesn't create all indexes when using different filters or names
Oct 1, 2019
This is a limitation in our Fluent API. s.HasIndex("RemoteId") will get or add the single index covering that property. Subsequent calls to HasFilter and HasName are overriding the configuration for that index.
@AndriySvyryd Can you work around this by dropping down to Metadata? Do we have an issue on our backlog about addressing indexes by name in the fluent API?
When you define multiple indexes for an entity over the same columns but with a different filter expression and/or name, EF will only create a migration statement for the last one.
Steps to reproduce
Create a project with this model:
RemoteId
, the name and filter for each index is different (I can create such indexes on SQL server with T-SQL)dotnet ef migrations add CreateInitialSchema
IX_State_RemoteId_ItemGroupId
.Further technical details
EF Core version: both 2.* and 3.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: netcoreapp2.2 / netcoreapp3.0
Operating system: Windows 10
IDE: N/A
The text was updated successfully, but these errors were encountered: