© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
10 replies
od

❔ EF8 SqlQuery with PostgreSQL, put variable as string in FormattableString

Hi,
I'm trying use SqlQuery with custom types.

_context.Database.SqlQuery<T>(@$"SELECT * FROM ""public"".{_tableName} WHERE ""Id""={Guid.Parse(id)}").SingleOrDefaultAsync();
_context.Database.SqlQuery<T>(@$"SELECT * FROM ""public"".{_tableName} WHERE ""Id""={Guid.Parse(id)}").SingleOrDefaultAsync();

Error:
Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "$1"
Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "$1"


This line getting error cause the method converting this query to
SELECT * FROM "public".@p0 WHERE "Id"=@p1
SELECT * FROM "public".@p0 WHERE "Id"=@p1
.
But I need that:
SELECT * FROM "public"."Posts" WHERE "Id"=@p0
SELECT * FROM "public"."Posts" WHERE "Id"=@p0


How can I do that?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

OData filtering string variable
C#CC# / help
3y ago
❔ Use Variable as Type
C#CC# / help
3y ago
❔ assign a local string function to a string variable
C#CC# / help
4y ago
Aspire custom connection string env variable
C#CC# / help
8mo ago