I have this class:
public class BSC
{
public int BSCId { get; set; }
public string BSCName { get; set; }
}
and the config class:
public class BSCConfig :EntityTypeConfiguration<BSC>
{
public BSCConfig()
{
Property(m => m.BSCName).HasMaxLength(50).HasColumnName("Category").IsRequired();
}
}
I want to make this property Unique, but I do not have isUnique or Index method.
Can you please tell me how to make this property Unique?
Use HasColumnAnnotation
:
Property(m => m.BSCName).HasMaxLength(50).HasColumnName("Category").IsRequired()
.HasColumnAnnotation("Index",
new IndexAnnotation(new IndexAttribute("IX_X_Category") { IsUnique = true }));
You can also do it with data annotations.
[Index("IX_X_Category", 1, IsUnique = true)]
public string BSCName { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With