Is it possible to add CHECK constraint with fluent API in Entity Framework 7?
I need to acheive something like this:
...
ADD CONSTRAINT CK_SomeTable_SomeColumn CHECK (SomeColumn >= X);
It is ok if solution is provider-specific - I am targeting MsSqlServer only (at least now).
As of EF Core 3.0, you can use
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SomeTable>(entity =>
entity.HasCheckConstraint("CK_SomeTable_SomeColumn", "[SomeColumn] >= X");
}
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