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())?
Insert a datetime causes error
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
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).
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).