check constraint entity framework

前端 未结 2 772
面向向阳花
面向向阳花 2020-12-03 14:08

IN EF can I add a check constraint so if my CustomerNotes entity has a boolean \"FollowUpRequired\" property I force user to enter a valid future date in the \"FollowUpDate\

2条回答
  •  青春惊慌失措
    2020-12-03 14:49

    EF Core 3.0 supports entity.HasCheckConstraint() now.

    To take Ryan's example:

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

提交回复
热议问题