Is it possible to add CHECK constraint with fluent API in EF7?

前端 未结 3 602
温柔的废话
温柔的废话 2020-12-19 00:18

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_         


        
3条回答
  •  情深已故
    2020-12-19 01:06

    As of EF Core 3.0, you can use

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity(entity =>
            entity.HasCheckConstraint("CK_SomeTable_SomeColumn", "[SomeColumn] >= X");
    }
    

提交回复
热议问题