I’m using PostgreSQL with Dapper.
My situation that I have 2 tables, GameRating
and Game
from 2 databases (difference connection string) .
First thing I select the most rating game like I have Count
and GameId
(data type is Guid).
Then at the table Game
, I want to order by like Count
of the GameId
. The data will like
ListGameIdCountResponse { Count = 1, GameId = 'xxxxx-xxxx-xxxx' }
Then I make the ListGameIdCount
into the string like this
var ListGameIdCount = string.Join(',', ListGameIdCountResponse.Select(p => $"('{p.GameId}',{p.Count})").ToList());
Example:
ListGameIdCount = ('xxxxx-xxxx-xxxx',10),('xxxxx-bbbb-xxxx',9)
So the query get trending game will like:
var query= SELECT g."Name",g."Id"
FROM "Games" g
LEFT JOIN (VALUES @GameIdList) as TrendingGameCount (GameId,Count)
ON g.""Id"" = TrendingGameCount.GameId ::uuid
ORDER BY TrendingGame.Count DESC
After that I use dapper to query
conn.Query(query, new { @GameIdList= ListGameIdCount})
The problem im facing now after binding the ListGameIdCount into the query it have double quote at the value
Example
LEFT JOIN (VALUES "('xxxxx-xxxx-xxxx',1))" as TrendingGameCount (GameId,Count)
What I want is
LEFT JOIN (VALUES ('xxxxx-xxxx-xxxx',1)) as TrendingGameCount (GameId,Count)
I try to replace or trim the double quote before binding data into query but it not work
Choi Xong Zong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.