Is it possible using the EF Fluent API to customize the Discriminator column and another row column to be part of a unique index constraint?
I have a list of identifiers, where identifiers can be of different types. Each identifier has a property of type string, which contains an identification string.
The client in my case may have different identifiers. But there can only be one identifier with a unique string per discriminator.
An abstract class defining the type of identifier
public abstract class CustomerIdentifier : Entity<int> { public string Identifier { get; set; } }
A specific class derived from CustomerIdentifier
class NationalIdNumberIdentifier : CustomerIdentifier { }
I managed to set up the index for the row column using the answer here, Unique key constraints for multiple columns in the Entity Framework as follows
class CustomerIdentifierMap : EntityTypeConfiguration<CustomerIdentifier> { public CustomerIdentifierMap() { Property(p => p.Identifier).HasMaxLength(100).IsRequired().HasUniqueIndexAnnotation("UQ_IdentifierPerDiscriminator", 0); } }
I need to somehow add another line that indicates that the discriminator should be included in the unique index constraint.
source share