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

Throw InvalidCastException with " ORDER BY DESC\ASC " when SqlMapper CONVERT a char-type-db-column TO a string-type-c#-property #2105

Open
AkazawaYun opened this issue Jul 29, 2024 · 0 comments

Comments

@AkazawaYun
Copy link

System.InvalidCastException:Error parsing column 0 (id='a-char-type-value-in-datebase' - Object)
in /_/Dapper/SqlMapper.cs:line 3928
at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value)
at Deserialize8cb9bee9-c2a8-4fec-bfdc-167531fec084(DbDataReader)

This is example:

public class user
{
public string id {get;set;} // char(36) in db
public int age {get;set;} // int in db
}
SELECT * FROM user WHERE true ORDER BY age ; =>this is OK !
SELECT * FROM user WHERE true ORDER BY age ASC ; =>this is Throw InvalidCastException !
SELECT * FROM user WHERE true ORDER BY age DESC ; =>this is Throw InvalidCastException !

Change the type of the id-column in mysql : char(36) → varchar(36) , then :

SELECT * FROM user WHERE true ORDER BY age ; =>this is OK !
SELECT * FROM user WHERE true ORDER BY age ASC ; =>this is OK !
SELECT * FROM user WHERE true ORDER BY age DESC ; =>this is OK !

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