-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
InvalidCastException when using DateTime as parameter value for DbType.Time #1164
Comments
@natehitze I was able to repro the issue you mentioned. I will get back to you shortly with more information. |
@natehitze I have found the source of the issue and I am working to see if I can make a PR to address that. Meantime as a work around try |
Thank you for looking into this. I've already solved my issue by using a TimeSpan object for the value: p.DbType = DbType.Time;
if (val != null)
{
var v = (LocalTime)val;
p.Value = new TimeSpan(v.Hour,
v.Minute,
v.Second);
}
return p; |
Looking deeper to this, I noticed it is by design and the way you have solved the problem, by passing TimeSpan, is the correct way. The change started from PR #269. |
Closing as this is by design. |
@JRahnama Thanks again for looking into it. Do you think this is worth including on the porting document? |
@natehitze we will talk about this inside our team, but meantime, if you want to, feel free to make a PR and update porting-cheat-sheet.md page. We will review that and when it gets approved it will be merged. Thanks again for the support. |
Added the only difference in functionality I've found so far, from dotnet#1164.
I'm not sure if this is a bug or something that would be nice to have documented in the porting advice document. I didn't write this code so I'm not sure if passing DateTime was a requirement for System.Data at some point or not 😄
System.Data.SqlClient worked fine with this:
In Microsoft.Data.SqlClient, using that parameter gave me this exception:
I changed my parameter from a DateTime to a TimeSpan as hinted in the exception message and it works as expected.
The text was updated successfully, but these errors were encountered: