i can't seem to find such warning in ef core documentation. and the (sort of) funny things is that the ef core 2.1 query translator itself does not parameterize the generated sql in values clauses. which can be seen if you replace the .fromsql line of your query with

.where(x => artnum.contains(x.artikelnummer)

which btw is the linq to entities equivalent of your query which translates and executes just fine, so i don't know why you bother with fromsql in this particular case.

but anyway, you can parameterize the fromsql query by including {0}, {1} etc. placeholders inside the sql string and pass values through params object[] parameters:

as with any api that accepts sql it is important to parameterize any user input to protect against a sql injection attack. you can include parameter place holders in the sql query string and then supply parameter values as additional arguments. any parameter values you supply will automatically be converted to a dbparameter

in your case it could be like this:

var placeholders = string.join(",",, i) => "{" + i + "}"));
var values = atrnum.cast<object>().toarray();

.fromsql("select * from table where artikelnummer in (" + placeholders + ")", values)

Related Query