-
Notifications
You must be signed in to change notification settings - Fork 294
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
Add Support for DateOnly & TimeOnly types on SqlDataRecord #3125
Comments
Could you provide a code sample? |
The general use is, populate a structured table variable that is sent to a stored procedure, but the SqlDataRecord is reused for each row by convention as to not duplicate the data many times for each row as it is being streamed as it would with say a DataTable. Let me know if this is an insufficient repo. What is handy is the data can be changing up until the moment it is streamed out. I have not used TimeOnly in this way yet but makes sense to include it.
|
@dckorben Thanks, so you are really asking for two features:
Is that correctly understood? |
I cannot make this cal fail, does it only fail later?
|
Let me check this. I haven't tried the object methods in a long time. I've only used the strongly typed lately. |
Fails on execution. System.InvalidCastException: 'Specified cast is not valid.' I guess the point here is a DateOnly or TimeOnly should work for
|
Just noting that SqlDataRecord implements IDataRecord; both are extremely old (I'd say mostly obsolete) types which haven't been updated for a very long time. For example, there's no way to generically read any type (in the same way that DbDataRecord has a generic But I'd also advise user to look at moving away from these largely obsolete types. |
I am not planning to add new APIs, but plan to prevent runtime errors. |
Too bad there isn't a modernized equiv, unless table types are going to be deprecated. |
As @roji mentioned, these are old design APIs, not heavily used today. If we see a lot of interest from the community on this issue, this can be considered in future.. but as of now this isn't on our priority list. |
@cheenamalhotra I plan to fix the TVP runtime issue |
Make SqlDecimalConvertToDecimal_TestInRange run on non-US systems fixes dotnet#3125 related to dotnet#2258
It does work in the latest 6 prerelease. |
@dckorben Thanks for confirming. I will let the team decide if anything else needs to be done here.. |
AFAIK there's nothing you can do with SqlDataRecord - and no performance - that can't be achieved with SqlDataReader, which is fully, actively supported (and is what SqlDataRecord uses under the hood). |
@roji SqlDataRecord (or DataTable) must be used a TVP parameter - so it still has it's uses. (And SqlDataRecord is more performant than DataTable in this scenario) |
Is it really, in a significant way? |
Also, isn't it possible to use DbDataReader for TVP (docs)? I get that it's probably more work etc., but still. |
It was for me in a production use case, yes.
Forgot about that approach (needing a lot of code/efffort yes) |
Can confirm. |
@dckorben so, just to check in, this is working as expected in v6.0.1? If so, I think we can close this one :) |
@benrr101 yes, but no new APIs - I guess you are not planning that? |
Yes, it is working but still the ask would be to add APIs and/or modernize this approach because of the performance gains that are possible. I can create a new issue for that, but from the tone of the thread, it looks like that would be a waste of time. |
Since DateOnly and TimeOnly were added to NET 6, there has been some limited changes to the API to add direct paths for these new types.
I'd like to see SetDate and SetTime added to SqlDataRecord to bypass the need to instantiate a DateTime each time for columns with SqlDbType.Date and SqlDbType.Time. Or alternatively, overloads to SetDateTime which take these types directly.
Current workaround is to convert to a full DateTime via .ToDateTime(TimeOnly.MinValue) each time.
The text was updated successfully, but these errors were encountered: