OrderBy lambda keeps changing with every search

3

I have a lambda search, which refers to information in a grid, but with each different query it changes the place information:

Indicadores = (Pegatodos().Where(f => f.STATUS == "A")
                       .Select(x => new 
           { SEQINDICFINANC = x.SEQ, DESCRICAO = x.DESCRICAO, SIGLA = x.SIGLA })
                         .OrderBy( x => x.SEQ)
                         .ToList())

It returns the main information of my grid:

NOME  datas    |   datas |  datas
seq    0           0         0
seq    0           0         0
seq    0           0         0
seq    0           0         0

But with each query for periods of different dates the position of seq changes, and I need them to always be in the same position.

    
asked by anonymous 31.07.2014 / 19:24

2 answers

1

The change was occurring in the same script as the same ordering done in C # I used in JS and it worked, Thanks

success: function (result) {
              var dataArray = [];
              var valarray = [];
              var datas = {}; 
              var total = 0;

              for (var j = 0, length = result.Datas.length; j < length; j++) {
                  var indicador = {};

                  for (var l = 0; l < result.Indicadores.length; l++) {
                      if (result.Datas[j].PKINDIC== result.Indicadores[l].PKINDIC) {
                          indicador.pkindic= result.Datas[j].PKINDIC;
                          indicador.descricao = result.Indicadores[l].DESCRICAO;
                          indicador.valor= result.Datas[j].VALOR;
                          indicador.dtas = result.Datas[j].DTA;
                          indicador.pkvari= result.Datas[j].PKVARI;

                          dataArray.push(indicador);
                      }
                  }
              }

              //#region BubbleSort DataArray

              for (var cont = 0; cont < dataArray.length; cont++) {
                  for (var cont2 = 0; cont2 < dataArray.length - 1; cont2++) {
                      if (dataArray[cont2].dtas > dataArray[cont2 + 1].dtas) {
                          var temp = dataArray[cont2 + 1];
                          dataArray[cont2 + 1] = dataArray[cont2];
                          dataArray[cont2] = temp;
                      }
                  }
              }

              //#endregion

After getting all the results in 2 different arrays and moving to a single one with the information I needed, I used a bubblesort method to sort being so, which I had not before and in transforming 2 arrays to 1 was reordering the information randomly and with this method after the transformation has created a fixed sort.

People thanks for the help, if anyone has a similar problem put here

    
05.08.2014 / 16:25
1

Just invert OrderBy with Select . Returning Select does not guarantee an ordered list:

Indicadores = (Pegatodos().Where(f => f.STATUS == "A")
              .OrderBy(x => x.SEQ)
              .Select(x => new { 
                  SEQINDICFINANC = x.SEQ, 
                  DESCRICAO = x.DESCRICAO, 
                  SIGLA = x.SIGLA })
              .ToList())
    
31.07.2014 / 19:39