Determining the range of value for a field in database by using db-migration

人盡茶涼 提交于 2019-12-02 07:55:15

The Range annotation is used by the Entity Framework to indicate how to validate the data prior to saving, and by MVC to generate client side validation. If you also wish to add a check constraint to the database you can do it in your Up migration:

    public override void Up()
    {
        //Sql to add a check constraint using Sql Server syntax:
        Sql(@"ALTER Table dbo.Tags 
        ADD CONSTRAINT chk_Size 
        CHECK (Size IN (1, 2, 3, 4))");
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!