2
I have a problem/difficulty, I have this following SQL query that I need to transform it into LINQ, but I am having problems in LINQ COUNT().
select m.id_marca, m.ds_marca, pm.ds_caracterist_tecnica_prdmca, count(fp.id_fornec_prod_marca_fpmarcot) as t from Produto_Marca pm
left join Fornecedor_Prod_Marca_Cotacao fp on fp.id_produto_marca_prdmca = pm.id_produto_marca_prdmca
join Marca m on pm.id_marca = m.id_marca
where pm.id_produto_prod = 98
group by m.id_marca, m.ds_marca, pm.ds_caracterist_tecnica_prdmca
order by t desc
follows LINQ code
var x = from a in produtoMarcaService.GetAll()
join b in FornecedorProdMarcaCotacaoService.GetAll() on a.IdProdutoMarca equals b.IdProdutoMarca into juncao
from c in juncao.DefaultIfEmpty()
join d in MarcaService.GetAll() on a.IdMarca equals d.IdMarca
where a.IdProduto == id
group c by new { d.DsMarca, d.IdMarca, a.CdProdutoMarca, a.DsCaracteristTecnica, a.DsComercialProduto } into f
select new
{
f.Key.DsMarca,
f.Key.IdMarca,
f.Key.CdProdutoMarca,
f.Key.DsCaracteristTecnica,
f.Key.DsComercialProduto,
Count = f.Count()
};
Have some way to leave the same as SQL?
By the Line Count leaves everyone who is zeroed with the number 1, Print:
Already with my Count by SQL all that are zeroed, are really zeroed, PRINT:
I found this solution but is there any way to improve? I talk about performance.
– Silvio Fernando
I usually use Dapper in these queries/reports querys to improve performance. But for your question specifically for LINQ I see no improvement.
– George Wurthmann