-
Notifications
You must be signed in to change notification settings - Fork 291
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
DateOnly Output SqlParameter #2092
Comments
I could also see some kind of generic type parameter solution helping here, but that probably increases the scope quite a bit. |
Yeah, I will have a look, but I doubt there is a simple, non-breaking fix. |
Yeah, I think this is a fundamental limitation: when defining an output parameter, you specify which database type you're expecting out (e.g. DbType.Date), but not what CLR type (i.e. DateOnly vs. DateTime). It's true that SqlClient could use the CLR type of the input parameter ( |
You have the same issue with ExecuteScalar as well. Seems the only working paths are SqlDataReader->GetValue / SqlParameter input values. Client code can build extensions methods / helper methods for converting DateTime to DateOnly and TimeSpan to TimeOnly, such as a It is also strange that an Input/Output SqlParameter takes a TimeOnly/DateOnly on the way in, but returns the result as DateTime/TimeSpan for the same parameter for a stored procedure. It is a narrow use-case, but that could perhaps be easily fixable to get a certain parity on the same object instance. If you start adding With the exception of the input/output SqlParameter case, I struggle to find a good solution. |
With ExecuteScalar, a user always has alternative of calling ExecuteReader instead and then using For output parameters, the way forward here is probably the introduction of a generic DbParameter (dotnet/runtime#17446), which is something that needs to be done anyway to allow writing parameters without boxing. At that point, you'd have a |
This is the optimal solution imo. Allows for very nice type safe constructors. |
@brandonryan Thanks for reporting. I am adding this to our enhancement list for future semester planning. |
Any news on this? It's been a almost year now... |
5.1.0 Preview 2 has a change that might be related to this to address issue #1009 , please review and let us know if it fixes this issue |
Problem
The new
DateOnly
CLR type maps nicely to the SQLdate
for input parameters now, but there is no way for me to tell the sql driver that I want sqldate
output parameters to beDateOnly
. (Potentially the same with TimeOnly instead of time span).Example
Exec Stored Procedure
Stored Procedure
Proposed Solution
It would be nice if there was some kind of configuration flag, or custom converter interface, but I'm not sure where you would put it.
An alternative solution could be using the Value parameter as a hint of what type is expected out. This feels a bit like magic behavior though, more meant as a last resort if configuration isn't an option.
The text was updated successfully, but these errors were encountered: