-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Dapper.Contrib - Update] SqlDateTime overflow error #33
Comments
I think it will be because your datetime properties "CreatedDate" and "LastUpdatedDate" aren't nullable. They will default to the minimum datetime in .Net code, which is January 1, 0001, in the Gregorian calendar. This is earlier than the minimum allowed by the SqlDateTime type (1/1/1753 12:00:00 AM). |
@Willberforce I'm not inserting new record, I'm updating existing one (the exiting record is valid). |
Have a look at the code - https://github.com/StackExchange/Dapper/blob/master/Dapper.Contrib/SqlMapperExtensions.cs In particular the method on line 403... ...and line 442... Although you are calling update - the c# object has a new DateTime on it as it isn't nullable. The Update extension method cycles through ALL the properties on the type (EC_Category) and will update the CreatedDate and LastUpdatedDate. |
Thanks for your time bro. |
Any update here?! |
Dapper is converting every property to it's SQL Equivalent, and this happens before any update is even done. In this case, it is converting your property, CreatedDate to a SQL Server DateTime datatype. Unfortunately, the C# default doesn't have an equivalent SQL Sever value, so you get that error. I don't ever update tables like your doing here, as I always use a stored proc. However, that won't necessarily fix this issue either, but it will give you much more flexibility when it comes to handling something like this. |
Hi,
I'm using Dapper
v1.50.5
v2.0.30
and Dapper.Contribv1.50.5
v2.0.30
, here is my model:And here is my code for update single record:
I got:
Dapper.Contrib
makesSQL
happy if I assign some value toCreatedDate
, e.g:CreatedDate = DateTime.Now
, but it is created date and should not be changed on each update.The text was updated successfully, but these errors were encountered: