I am faced with casting issue when calling a stored procedure that has two select queries where only one of the query will be executed based on an if else condition. BOTH the select queries have the same values being selected, but in different order. Just to give an idea,
IF (some condition)
SELECT
t1.Id,
t1.Title,
t1.Description
FROM Table1 t1
ELSE
SELECT
t1.Title,
t1.Id,
t1.Description
FROM Table1 t1
Scenario:
- Method that executes this stored procedure is called, condition is satisfied.
- Expected data is returned.
- Method that executes this stored procedure is called, condition is not satisfied.
- Casting error thrown in code.
Error parsing column 0 (Id=123 - Int64)
System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.String'.
at Deserializec2c12182-6e8d-4a6e-8f54-e60138f070ee(IDataReader )
Changing them to the same selection order will bypass the issue, but can anybody tell if this is some caching issue with Dapper, or anything else?
Any help is appreciated. Thanks.