Skip to content
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

Querying int columns as strings has broken in 2.1.37 #2056

Closed
sellotape opened this issue Mar 14, 2024 · 6 comments
Closed

Querying int columns as strings has broken in 2.1.37 #2056

sellotape opened this issue Mar 14, 2024 · 6 comments

Comments

@sellotape
Copy link

Might be intentional, but worked in 2.1.35, and I suspect a lot of people will be depending on it and pretty surprised, as there's no mention of a breaking change in the release notes.

To replicate, simply (I'm using Azure SQL Server):

using IDbConnection cx = new SqlConnection("your-connection-string");
string? actual = await cx.QueryFirstOrDefaultAsync<string>("select id from someTableWithAnIntIdColumn").ConfigureAwait(false);

In 2.1.35, this returns e.g. "42". In 2.1.37 it throws System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'System.String'.

Fuller exception:

System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'System.String'.
   at Microsoft.Data.SqlClient.SqlDataReader.GetFieldValueFromSqlBufferInternal[T](SqlBuffer data, _SqlMetaData metaData, Boolean isAsync)
   at Microsoft.Data.SqlClient.SqlDataReader.GetFieldValueInternal[T](Int32 i, Boolean isAsync)
   at Microsoft.Data.SqlClient.SqlDataReader.GetFieldValue[T](Int32 i)
   at Dapper.SqlMapper.<>c__DisplayClass209_0`1.<UnderlyingReadViaGetFieldValueFactory>b__0(DbDataReader reader) in /_/Dapper/SqlMapper.cs:line 3134
   at Dapper.SqlMapper.QueryRowAsync[T](IDbConnection cnn, Row row, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 496
   at <my test code>
@mgravell
Copy link
Member

That's because we didn't know it was a break. This is related to the GetValue change for strings, to mitigate against a npgsql behaviour.

I've unlisted - will think of best path forward, probably a revert.

@mgravell
Copy link
Member

Xref #2049 #2050

@mdx0111
Copy link

mdx0111 commented Apr 12, 2024

I have the same problem with decimal to string.
Thanks

@mgravell
Copy link
Member

Yup, we need to revert a change there (which is why 2.1.37 is hidden); I'll do that now

@mgravell
Copy link
Member

#2070

@mgravell
Copy link
Member

https://github.com/DapperLib/Dapper/releases/tag/2.1.42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants