Insert a datetime causes error

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Microsoft SQL Server
Post Reply
Blave
Posts: 9
Joined: Fri 23 Sep 2011 12:46

Insert a datetime causes error

Post by Blave » Wed 07 Dec 2011 08:24

I have a table USER contains:

ID int,
NAME varchar(50),
CREATED datetime default getdate()

It throw an error LinqCommandExecutionException (SqlDateTime overflow) while I did this:

USER user = new USER();
user.ID = 1;
user.NAME = "AAA";
// user.CREATED is not provided, so it will use default value(getdate())
dataContext.USERs.InsertOnSubmit(user);
dataContext.SubmitChanges(); // Error

How can I Insert a row without provide a column with default value(getdate())?

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 08 Dec 2011 16:29

Thank you for the report. At the moment, the default values are used in the generated code, but only in the case they can be parsed as the .NET data type of this particular entity property. As 'getdate()' cannot be parsed as DateTime, no value is set by default in the 'CREATED' field of the 'user' object.

We will consider supporting the server functions setting the default values, and post here about the results.

At the moment, you can change the default value of 'CREATED', e.g., to 'DateTime.Now' (in this case, the time will be determined on the client machine, not on the server) or mark this property as auto-generated and synchronized on inserts (in this case, you won't be able to explicitly specify the 'CREATED' value).

Post Reply