eswartechraq / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

datetime2 column with MinValue throwing SqlDateTime overflow exception #157

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an object with DateTime property and a value of DateTime.Min
2. Call Query<int> with the Insert and SCOPEIDENTITY on the end
3. Execute SQL
4. result.First() throws SqlDateTime overflow. Must be between 1/1/1753 
12:00:00 AM and 12/31/9999 11:59:59 PM.

What is the expected output? What do you see instead?
I expect it to insert into my table. Writing the raw SQL and inserting with 
date of 0001-01-01 works fine. I see an exception instead

What version of the product are you using? On what operating system?
1.12.1.1

Please provide any additional information below.

Original issue reported on code.google.com by jonathan...@gmail.com on 17 Oct 2013 at 10:06

GoogleCodeExporter commented 8 years ago
This is because Dapper uses a typeMap that maps DateTime to DbType.DateTime, 
rather than DbType.DateTime2.  If you've included the Dapper source, you can 
change the mapping by modifying the source:

    typeMap[typeof(DateTime)] = DbType.DateTime2;

If you're using a binary version of Dapper, you can change the mapping by 
calling:

    SqlMapper.AddTypeMap(typeof(DateTime), DbType.DateTime2)

but be aware that the AddTypeMap method is not thread-safe: 
http://code.google.com/p/dapper-dot-net/issues/detail?id=165&start=100

Original comment by Jocular...@hotmail.com on 30 Nov 2013 at 2:16