1

If a user does something like this inside OnModelCreating:

modelBuilder.Entity<MyBaseEntity>.HasDiscriminiator(x => x.EntityType)

Outside OnModelCreating, is it possible to either get the full list of discriminator columns or check if a particular column was configured as discriminator?

Thanks.

1 Answer 1

0

In EF Core 3.x it can be obtained for a given IEntityType using the GetDiscriminatorProperty method, e.g.

var discriminatorProperty = dbContext.Model
    .FindEntityType(typeof(MyBaseEntity))
    .GetDiscriminatorProperty();

Some other useful extension methods are GetDiscriminatorValue, GetDerivedTypes, GetRootType etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.