Using KEY element

4

In my model, I use a view that is built on certain table joins, which do not have any auto-incremental ID elements.

My model requires that I assign a TAG Key , however, since I do not have any single-valued elements, I'm getting problems.

How could I take the need of Key or even generate a pseudo ID?

    
asked by anonymous 12.02.2016 / 19:21

1 answer

2
  

How could I take the need of the Key or even generate a pseudo ID?

The most interesting way to do this is to unify all the structures in a ViewModel with one more property. Let's call linha .

When developing the enumeration that goes to View , do the following:

var listaParaView = new List<ElementoViewModel>();
int i = 0;
foreach (var elemento in PrimeiraLista)
{
    listaParaView.Add(new ElementoViewModel 
    {
        Linha = i++,
        // Coloque os demais elementos aqui    
    });
}

foreach (var elemento in SegundaLista)
{
    listaParaView.Add(new ElementoViewModel 
    {
        Linha = i++,
        // Coloque os demais elementos aqui    
    });
}

return View(listaParaView);
    
12.02.2016 / 19:49