This is the first in (hopefully) a series of quick things I’ve picked up whilst tackling the previously mentioned project.
So, I have a table something like this:
CREATE TABLE [dbo].[Product](
[ProductID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](100) NOT NULL,
[Price] [int] NOT NULL,
[LastSaveTimestamp] [datetime] NOT NULL CONSTRAINT [DF_Product_SaveTimestamp
The key here is the default value on the column: LastSaveTimestamp.
If I then try to, say insert a new column into this table, for example using this code:
DatabaseContext dc = new DatabaseContext();
Product product = new Product();
product.Name = “test product”;
product.Price = 50;
dc.Products.InsertOnSubmit
Then I’d get an exception like:
System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM..
The fix is actually really simple – In the table designer / DBML, you need to tell it that the column is auto-generated. Unfortunately this doesn’t seem to be automatically detected. It’s one of a few ‘just plain weird’ situations.
AzamSharp has the fix details, with a handy-dandy screenshot over on his blog.