This is a migrated thread and some comments may be shown as answers.

Default DateTime value insert error

5 Answers 141 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jacek
Top achievements
Rank 1
Jacek asked on 16 Oct 2012, 01:09 PM
Hi

I have a NOT NULL column of DateTime type with default getdate()  (only DateTime column in this table).
Wizard set HasDefaultValue for this column to true (properly).

Can anyone tell me why following code

EntitiesModel context = new EntitiesModel();
MyTable c = new MyTable();
context.Add(c);
context.SaveChanges();

throws an error as below?

Insert of '79698738-' failed: System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

(meaning that value of zero date has been set by ORM rather than by SQL Azure server itself)
It's either very simple misunderstanding or something is very wrong.
OpenAccess 2012.2.816.1

Thanks,
Jacek

5 Answers, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 22 Oct 2012, 11:40 AM
Hello Jacek,

That is the expected behavior of Telerik OpenAccess ORM. The HasDefaultValue property is a boolean flag which marks the columns containing default values. In order for OpenAccess to skip this column from the insert statement when you add a new object you need to define the property mapped to this column as Nullable.

You can do that by following these steps:
    - Open the .rlinq file
    - Find the domain class that contains the property to which the column is mapped
    - Select the property and press F4 to open the Properties window
    - Find the Nullable propety and set it to True
    - Save the .rlinq file

If you experience any difficulties with the implementation of the solution or you have more questions, do not hesitate to get back to us.

Greetings,
Doroteya
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
0
Jacek
Top achievements
Rank 1
answered on 22 Oct 2012, 12:46 PM
Hi,

I've set as requested and...

Insert of '1041742352-' failed: Telerik.OpenAccess.RT.sql.SQLException: Cannot insert the value NULL into column 'mydate', table 'dbo.TestTable'; column does not allow nulls. INSERT fails.


Table
CREATE TABLE [dbo].[TestTable](
    [myid] [uniqueidentifier] NOT NULL,
    [mydate] [datetime] NOT NULL,
 CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED
(
    [myid] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF)
)
GO
 
ALTER TABLE [dbo].[TestTable] ADD  DEFAULT (newid()) FOR [myid]
GO
 
ALTER TABLE [dbo].[TestTable] ADD  DEFAULT (getdate()) FOR [mydate]
GO

rlinq settings in attachments

Thanks,
Jacek

0
Doroteya
Telerik team
answered on 23 Oct 2012, 12:14 PM
Hi Jacek,

I tried to reproduce the described behavior on MS SQL Azure with the database script you provided and the settings from the screenshots. The Telerik OpenAccess ORM versions I tested are 2012.2.816 and 2012.3.1012, and the Visual Studio versions are 2010 and 2012. However, everything works fine on our side.

I am sending you the assembly for OpenAccess 2012.2.816 with Visual Studio 2010. To run it just add your connection string in both App.config files and build the solution.
 
In the mean time I suggest you to create a new test application with a new domain model with the necessary setting and try your code again.

My best guess is that there is something wrong with the current model you use and in order to continue looking for the cause of this behavior, I will ask you to send to open a support ticket and attach the .rlinq file.

I am looking forward for your replay.


Greetings,
Doroteya
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
0
Jacek
Top achievements
Rank 1
answered on 24 Oct 2012, 05:36 PM
Hi,

Ticket # 621906

Thanks,
Jacek
0
PetarP
Telerik team
answered on 29 Oct 2012, 01:56 PM
Hi Jacek,

 As pointed in the internal support inquiry you have created - currently defining default values with the fluent api is not supported. We will be looking into the possibility to add support for this feature with our service pack for the Q3 release.

Greetings,
Petar
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Tags
General Discussions
Asked by
Jacek
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Jacek
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or