quaiton89 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Error parsing column 4 (ChildrenCount=1 - Int64) #124

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It seemed that the latest version of Dapper have a bug about mapper cache?

ChildrenCount is from following sql:
sql = "select d.ID, d.Version, d.DName, d.Position, count(distinct child.ID) 
ChildrenCount ..."

when execute following code twice with diffrent whereEntity:
connection.Query<fooClass>(sql, whereEntity).ToArray();
(fooClass has a property ChildrenCount which type is long)

If first time execute have at least a record return, Dapper works well.But if 
first time execute return no record, second execute will cause a exception as 
this issue title.

Original issue reported on code.google.com by hncd...@gmail.com on 28 Nov 2012 at 7:30

GoogleCodeExporter commented 8 years ago
Yes. I have exactly the same problem. After I rebuild REST project with Dapper 
and SELECTING first time where no records are returned, second SELECT throws 
Error parsing column ...
Rebuilding the project again and SELECTING first time where rows are returned, 
everything works later.

Original comment by n.narmontas@gmail.com on 26 Jun 2013 at 3:35

GoogleCodeExporter commented 8 years ago
And I found the solution. Dapper is strict on mapping different types. So you 
need to make sure that first and subsequent queries return the same schema.

In example I made some workaround in MySQL stored procedure so that it should 
always return the same schema if no rows are returned:

a) if stored procedure returns one or more rows:
SELECT id, name FROM table ...; (where `id` is SIGNED INTEGER, and `name` is 
VARCHAR)
b) if stored procedure happens to return ZERO rows I return "empty schema":
SELECT CAST(1 AS SIGNED) id, CAST(2 AS CHAR) name LIMIT 0;

Now dapper mapper caches correct schema and does not fail.

Original comment by n.narmontas@gmail.com on 26 Jun 2013 at 4:28