3
I am trying to execute a query by passing as clause an 'in' with integers, this is the code so far:
public List<Pedido> GetByUsuario(List<GestorVendedor> gestorVendedor)
{
int[] seller_id = new int[gestorVendedor.Count];
for (int i = 0; i < gestorVendedor.Count; i++)
{
seller_id[i] = gestorVendedor[i].id;
}
return _dbContext.Pedido.FromSql("select * from dbo.vendas where seller_id in ({0})", String.Join(",", seller_id)).ToList();
}
With this code problem occurs in the conversion as shows the error message:
'Conversion failed when Converting the nvarchar value '1,2,3' to data type int.'
How to get around this problem?
Do a test: string query = $"select * from dbo.sales Where seller_id in ({String.Join(",", seller_id)})" You are giving a . Tolist() in Fromsql(). Tolist()
– Geilton Xavier Santos de Jesus
Hello Geilton, executed as you passed, however it gives an injection vulnerability alert! Sorry to stretch but there’s a right way to do this?
– Alessandro