We're getting close. With that code, it almost worked. Then I changed the % from% to Distinct()
and did not repeat, but still does not obey the DistinctBy()
. What comes in linq does not match query . In all Reasons I brought UN's , and in the Reason for IDMotivo
, I should only have 2 UN's strong>, which seems to be bringing the same information, regardless of ID=4
.
I'm here trying to find a solution. Here's how my code went:
public static List<MontaArvoreAcao> CriarListaArvoreAcao()
{
RupturaEntities db = new RupturaEntities();
var _listaUnidade = (
from r in db.Ruptura
join a in db.Apresentacao on r.Codigo_Apresentacao equals (a.Codigo_Apresentacao)
join m in db.Motivo on r.IDMotivo equals (m.IDMotivo)
where r.IDMotivo != 6
group r by new { a.Unidade_Negocio, r.IDMotivo } into gr
select new MontaArvoreAcao
{
IDMotivo = gr.Key.IDMotivo,
Unidade_Negocio = gr.Key.Unidade_Negocio
}).DistinctBy(u => u.Unidade_Negocio)
.DistinctBy(m => m.IDMotivo)
.ToList().OrderBy(r => r.IDMotivo);
return _listaUnidade.ToList();
}
As it stands, without the IDMotivo
, I can bring all the UN's . Bringing a UN reading like this:
{GENÉRICOS,MIP,DERMOCOSMÉTICOS},
{DERMOCOSMÉTICOS,MIP,GENÉRICOS},
{MIP,GENÉRICOS,DERMOCOSMÉTICOS},
{DERMOCOSMÉTICOS,GENÉRICOS},
{MIP,GENÉRICOS,DERMOCOSMÉTICOS}
For the respective Reasons:
{VENDEU TODO ESTOQUE},
{PRODUTO EM FALTA NO CENTRO DE DISTRIBUIÇÃO},
{PRODUTO NÃO CADASTRADO NA CENTRAL},
{PRODUTO INATIVO},
{PRODUTO CADASTRADO / SOB ENCOMENDA}
Which represent respectively the ID's: 1,2,3 and 4 . You can see that you brought me in as query , but I can not redistribute for each Reason.
How is my screen :
My screen creates the first node with the DistinctBy
for each checkbox
. The reasons are listed correctly and Motivo
are created correctly.
Correct is to list, for each checkbox
, the corresponding Motivo
. It may be missing something, some ID, but which one?
I got to the point that I did not know anything else. It should be UN's
to Distinct
appropriate, but how do I do this? This is my cruel doubt that I am passing.
But that way I brought them all right. What is missing is the correct distribution for each ID
matching. I'm waiting and thank you