Query with JOIN clause always returns a empty result set using Dapper

c# dapper

Question

I trying to do the following query using dapper but its always returning a empty result set. First I tried to remove the WHERE clause in order to isolate the problem but that didn't work. After that I added a alias to the C.NAME column in the SELECT clause but didn't work either.

private const string SelectClaims =
 @"SELECT C.NAME FROM CLAIMS C 
  INNER JOIN USERS_CLAIMS UC ON C.ID = UC.ID_CLAIM 
  WHERE UC.ID_USER = @Id";

using (var conn = new FbConnection(connectionString))
{
    var claims = conn.Query<string>(SelectClaims, new { user.Id });
    return claims;
}

If I replace the query above for this right here everything works fine:

SELECT NAME FROM CLAIMS

Accepted Answer

So, I put this aside and go do something else and after I came back to try to solve my problem everything was working fine. I didn't change anything in my code and surprisingly its working right now.

I don't know if is possible that a pending transaction in my MiTeC Interbase Query was blocking me to see the current records from the database. I try to simulate this again and now its always returning the records that I need (better that than nothing, hehe).

For clarification, its perfect fine to use a string as the returning data type, do a simple join in sql parameter to a Query method or don't use a alias for the returning column at all (only if all columns matches your C# property names or you just have a column directing to a string like me).


Popular Answer

To be honest I am not sure if you are using Dapper properly since you are selecting named column and mapping it to simple string - I believe Dapper doesn't see 'Name' property as fails silently. I guess you should try either Query<T> with strongly typed object or use Query<dynamic> to avoid unnecessary class creation.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why