I'm trying to execute a query using ExecuteInterpolatedSqlAsync
that checks if a specific substring is included in an array of integers.
What I've tried is this:
var value = "example";
var integers = new List<int> { 100, 404, 777 };
FormattableString query =
$"DELETE FROM Table1
WHERE Type = {value}
AND CAST(SUBSTRING(Value, 5, 7) AS INTEGER) IN ({string.Join(",", integers)})";
await _signInDbContext.ExecuteSqlInterpolatedAsync(query);
When I debug this, it shows the string as follows:
DELETE FROM Table1 WHERE Type = example AND CAST(SUBSTRING(Value, 5, 7) AS INTEGER) IN (100,404,700)
But when it runs the query against the Database it puts quotes around both parameters:
DELETE FROM Table1 WHERE Type = 'example' AND CAST(SUBSTRING(Value, 5, 7) AS INTEGER) IN ('100,404,700')
This makes sense because both are a string. But it's not what I want (obviously), I get this error:
Conversion failed when converting the nvarchar value '100,404,777' to data type int
How can I include an integer array in this ExecuteSqlInterpolatedAsync
query?