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 anyone else experienced this behaviour? Is there a way to fix it, so that Linq-to-SQL or SQL Server automatically sets the default value?
The column I added was of type Bit, with a default value set to 1.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With