My EF Core discriminator column is created like this
modelBuilder.Entity<MyClass>()
.HasDiscriminator<string>("MyDiscriminator")
.HasValue<SubClass1>(nameof(SubClass1))
.HasValue<SubClass2>(nameof(SubClass2))
... etc.
The property MyDiscriminator is not defined on MyClass - its added automatically, However the SQL table created has the column MyDisciminator defined as nvarchar(max) The values in the discriminator column can only be from the list defined, i.e. "SubClass1", "SubClass2" etc.
If I attempt to index the discriminator column I get
Msg 1919, Level 16, State 1, Line 29
Column 'MyDiscriminator' in table 'dbo.MyClass' is of a type that is invalid for use as a key column in an index.
Is there any way to define a string discriminator so the max length can be set to something more reasonable - and that can be indexed?
Or if not could there be any pitfalls in changing it manually in the database using something like
ALTER TABLE dbo.MyClass
ALTER COLUMN MyDiscriminator nvarchar(50)