Linq-to-SQL ignores SQL Server default value

后端 未结 6 1523
感情败类
感情败类 2020-12-15 17:59

When using Linq-to-SQL, adding a column to an existing table, and setting a default value on that new column, it seems that Linq to SQL ignores the default value. Has anyon

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 18:32

    If you ever need to change the value in your own code (eg. a type table value with a default) then don't use 'Auto Generated Value' or you'll get this later when you try updating it.

    Value of member 'AlternativeQuoteStatus' of an object of type 'OrderDetail' changed. A member that is computed or generated by the database cannot be changed.

    I prefer to set such values when I create the object, with a fallback in OnCreated as described by others here.

提交回复
热议问题