4
Hello, everybody.
I have a situation, where I concatenate some subquerys Sqls that are concatenated into other Sqls queries, to return some values.
I have several functions like these, because I use them in several other queries. So I don’t need to repeat code.
I would like to know how I can do this using Linqsql + EF.
Follow the example of a simple code.
public void Disponivel()
{
string query = "Select prod.Cod, prod.Descricao, ";
query += QueryEstoqueDisponivel("prod.Cod") + " as EstoqueDiponivel ";
query += " From TAB_Produtos prod ";
//Aqui será gerado uma lista dos produtos...
}
public string QueryEstoqueDisponivel(string aliasProduto = "prod.Cod")
{
string query = "((Select Sum(est.Quantidade) " +
" From ProdutoEstoque est " +
" Where est.CodProdutos = " + aliasProduto +
" ) " +
" - (Select Sum(it.Quantidade) " +
" From PedidosItens it " +
" Where it.CodProdutos = " + aliasProduto +
")" +
") ";
return query;
}
I can only give you a hint, your code is extraordinarily insecure. Rethink this.
– Maniero
The above code is just an example we need to do with Ingl. What do you mean by insecure?
– Fabiano Richetti
That even a child will invade whatever you’re doing there.
– Maniero
What version of C# are you using? You can use string interpolation in the query = $"" and pass the other parameters, query = $"select * from {substring1} from {substring2}"
– João Paulo Amorim
As I asked above, I need to do....
– Fabiano Richetti