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
{{ message }}
Repository navigation
Document discriminator column max length changes in EF8 #4655
In one of our applications, we have a THP structure for some of our models. In the previous versions, EF added the Discriminator shadow property to our models automatically and its length has been set to Max.
Problem Statement
By upgrading the EF and the .Net version to 8, by adding a new database migration using the following command, EF adds an update to the Discriminator to shrink its length: dotnet ef migrations add NewMigrationName
After adding the migration, when we want to apply it to the database using dotnet ef database update, it shows the following error message:
The index 'dta_index_organizations' is dependent on column 'Discriminator'. ALTER TABLE ALTER COLUMN Discriminator failed because one or more objects access this column.
The mentioned index in the above error message is also generated by EF automatically.
We manually added the Discriminator column to the models without setting the MaxLength for it and followed the different ways of configuring the Discriminator columns mentioned here to bypass the automatic updates, but nothing changed.
Provider and Version Information
EF Core version: 8.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: MS Windows 10
IDE: Visual Studio 2022 17.8.6
Note for team: the index exception is unfortunate here. We don't create indexes for discriminators by default, but an index will be created if the discriminator is part of a key.
changed the title [-]Issue with the Discriminator column after upgrade to version 8.0[/-][+]Document discriminator column max length changes in EF8[/+]on Feb 14, 2024
Activity
ajcvickers commentedon Feb 12, 2024
@AminEsmaeily You can configure the max length as unspecified again like this:
Note for team: the index exception is unfortunate here. We don't create indexes for discriminators by default, but an index will be created if the discriminator is part of a key.
AminEsmaeily commentedon Feb 12, 2024
Thank you @ajcvickers , the issue is fixed now
[-]Issue with the Discriminator column after upgrade to version 8.0[/-][+]Document discriminator column max length changes in EF8[/+]Updates to breaking changes
Updates to breaking changes
Updates to breaking changes (#4673)