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
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.
Set Auto Generated property to True.
I was faced the same problem of boolean data type with default as false and not updating that value So when i see the database table, i was found there is not primary key was set, therefore when i was set the primary key it was updated find. so check a table if it has the primary key or not.
Go into the designer and select "Auto-Sync" value of "OnInsert". This will sync the value when the record is inserted into the database.
I've seen this. What you can do is go into the l2sql designer, view properties for the table column that has a default value. There is a property "Auto generated value", set that to true.
This same value is set to true automatically for the identity column automatically, as in that case SQL Server is generating your row IDs.
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.