Charles Charles - 1 year ago 144
C# Question

EF Core HasDiscriminator with nullable discriminator

I'm trying to specify that I already have a discriminator on the entity, but am not sure how to represent it here.

The discriminator between them is whether or not a column is null. Obviously the case where it is null I can just put that explicitly, but what do I do for the case where its not?

protected override void OnModelCreating(ModelBuilder modelBuilder) {
.HasValue<ManagerSchedule>(/* What goes here? */);

Answer Source

Solved it by putting the property bool IsManagerSchedule on Schedule, and then using .HasValue<ManagerSchedule>(true).HasValue<EmployeeSchedule>(false);.