How to set a default value on a Boolean in a Code First model?

前端 未结 5 591
孤独总比滥情好
孤独总比滥情好 2020-12-31 00:13

I have an existing table / model into which I want to drop a new Boolean column. This table already has many hundreds of rows of data, and I can\'t touch the existing data.

5条回答
  •  清酒与你
    2020-12-31 00:35

    You can simply avoid auto-implemented properties and set the property value to true when you initialize your object.

    private Boolean _isReleased = true;
    public Boolean IsReleased 
    { 
        get
        {
            return _isReleased;
        }
        set
        {
            _isReleased = value;
        }
    }
    

提交回复
热议问题