Using KEY element

Asked

Viewed 30 times

4

In my model, I use a view that is built on the basis of certain joins of tables, which have no auto incrementable ID element.

My model requires that I assign a TAG Key, however, as I have no single value element, I am getting problems.

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

  • How do you return these unions? You are using SQL or linq?

1 answer

2

How could you take away Key’s need or even generate a pseudo ID ?

The most interesting way to do this is to unify all the structures into one Viewmodel with one more property. Let’s call linha.

In developing the enumeration going to the 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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.