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

Cannot QueryFirstAsync with Enum Type #81

Open
AdamDiament opened this issue Nov 20, 2022 · 0 comments
Open

Cannot QueryFirstAsync with Enum Type #81

AdamDiament opened this issue Nov 20, 2022 · 0 comments

Comments

@AdamDiament
Copy link

AdamDiament commented Nov 20, 2022

V 1.0.4

Given this query:

await connection.QueryFirstAsync<MyEnumType>("select MyEnumColumn from table where id = @id",parameters)

with this setup

connection.SetupDapperAsync(c => c.QueryFirstAsync<MyEnumType>(It.IsAny<string>(),
                    It.IsAny<object>(),null,null,null))

An exception is thrown:

"The value passed in must be an enum base or an underlying type for an enum, such as an Int32. (Parameter 'value')"

with strack trace

at System.Enum.ToObject(Type enumType, Object value)\r\n   at Dapper.SqlMapper.QueryRowAsync[T](IDbConnection cnn, Row row, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 480\r\n 

However this query and setup works fine

await connection.QueryFirstAsync<int>("select MyEnumColumn from table where id = @id",parameters)
connection.SetupDapperAsync(c => c.QueryFirstAsync<int>(It.IsAny<string>(),
                    It.IsAny<object>(),null,null,null))

It works but I don't want to change my code to less strongly typed, just to make my tests pass.

@AdamDiament AdamDiament changed the title Cannot queryfirstasync with enum type Cannot QueryFirstAsync with Enum Type Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant