EF Core 2.1 throws warnings about SQL injection. There is my code snippet where it happens
var query = await _ctx.Set<TABLE>()
.FromSql("Select * from TABLE where Artikelnummer IN (" + string.Join(',', artNum) + ")")
.AsNoTracking()
.Select(z => new
{
z.Artikelnummer,
z.Property
}).ToArrayAsync();
where artNum(stands for Artikel Numbers) is array of int numbers, like [1,22,34 etc.].
I can't pass artNum as parameters in FromSql, because there will be single quotes and SQL throws an exception.
I can rewrite the FromSql to
.Where(x => artNum.Contains(x.Artikelnummer))
But I have queries that much bigger and complicated than this one, so LINQ to Entities isn't good in this situation. there should be So, the question is how to rewrite this query so warning won't occur?
LINQ to Entities executes much longer than LINQ to SQL, so it's not appropriate way to solve my problem.
I investigated that concatenation causes warnings, so there should solution without concatenation.