Has there a way to create a compost unique index in fluente api based on some value ?
Ex:
string code { get; set; }
bool active { get; set; }
Property(x => x.code)
.HasMaxLength(6)
.HasColumnAnnotation(
IndexAnnotation.AnnotationName,
new IndexAnnotation(new IndexAttribute("IX_CODE", 1) { IsUnique = true }))
.IsRequired();
Property(x => x.active)
//I want this only if "active == true"
.HasColumnAnnotation(
IndexAnnotation.AnnotationName,
new IndexAnnotation(new IndexAttribute("IX_CODE", 2) { IsUnique = true }))
.IsRequired();
This didn't work for me because I want my "code" to be unique only when my "active" is true, otherwise I can have duplicated codes (with active == false).
Anyone knows a way ?