EF Core HasDiscriminator with nullable discriminator

asp.net-core c# ef-code-first entity-framework entity-framework-core

Question

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) {
    modelBuilder.Entity<Schedule>()
        .HasDiscriminator<Guid?>("ManagerId")
        .HasValue<EmployeeSchedule>(null)
        .HasValue<ManagerSchedule>(/* What goes here? */);
}
1
0
6/2/2016 2:42:26 PM

Accepted Answer

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

1
6/2/2016 7:39:08 PM

Popular Answer

Try removing the manual configuration and then:

public class EmployeeSchedule {
    // properties of all employees...
}

public class ManagerSchedule {
    public TYPE PropertyName {get; set;} // discriminator property
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow