Linq-to-SQL ignores SQL Server default value

后端 未结 6 1506
感情败类
感情败类 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:06

    I have now definitively fixed this by using an example from this blog.

    partial void OnCreated() {
        if (this.DateTimeCreated == null) {
               this.DateTimeCreated = DateTime.Now;
        }
    }
    

    I needed to pass this into a partial datacontext class, as the default one is automatically overwritten every time you change something in the dbml.

提交回复
热议问题