Throw InvalidCastException with " ORDER BY DESC\ASC " when SqlMapper CONVERT a char-type-db-column TO a string-type-c#-property
AkazawaYun opened this issue · 0 comments
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 !