Linq returns result, but does not obey join

1

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.

So when I'm going to list the UN's, each one below their corresponding motif, is that it does not work properly, that is, for each Reason created on the page, I've drawn all those Reasons at once for each Reason.

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

    
asked by anonymous 24.09.2014 / 13:06

1 answer

1

Solved. I made the differentiation in View itself and now it worked. Here's how it went:

<ul>
    @foreach (var item in Model)
    {
        if (_motivo != @item.Motivo)
        {
            _idmotivo = @item.IDMotivo;
            <li item-checked='false' item-expanded='false'>
                @item.Motivo
                <ul>
                    @foreach(var un in (List<Ruptura.Models.MontaArvoreAcao>) ViewData["ListaUn"])
                    {
                        if (@un.IDMotivo == @item.IDMotivo)==> ***aqui resolveu***
                        { 
                            <li item-checked='false' item-expanded='false'>
                                @un.Unidade_Negocio
                            </li>
                        }
                    }
                </ul>
            </li>
        }
        _motivo = @item.Motivo;
    }
</ul>
    
24.09.2014 / 14:34