I can't figure out how to use a List<Guid> as a parameter in my query. I've had trouble with this for some time in different situations, but here is the current one. I'm trying to cleanup after tests by deleting everything created by a test user. Here's the code:
var idList = new List<Guid>() { SYS_ADMIN_GUID, OPERATOR_GUID, OPERATOR_ELECTRONICS_TECH_GUID, UNIT_MANAGER_GUID, AREA_MANAGER_GUID };
using (NpgsqlConnection c = new NpgsqlConnection(TestHelper.ConnectionString))
{
c.Open();
c.Execute(@"delete from ""BlueStakes"".""MarkRequestStatuses"" where ""CreatedById"" in :idList", new { idList });
}
I've also tried to use @idList as the parameter which didn't work either. This is the error that it is giving:
Npgsql.PostgresException: Npgsql.PostgresException: 42601: syntax error at or near "$1"
Obviously the query isn't recognizing the list and sticking it in for the parameter but I can't figure out why.
You can't use IN with a list in PostgreSQL. To check if an element exists in a list, use the following syntax: WHERE "CreatedById" = ANY (:idList).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With