How to order a Collection according to the Date and Time in C#?

Asked

Viewed 89 times

0

I need to order the Personal Collection?

You’re not ordering... Someone knows how to do this?

public Pessoa GetJoinById(int id)
{
    var pessoa = Db.Pessoa.Find(id);

    Db.Entry(pessoa)
         .Collection(x => x.PessoasGenericos)
         .Query()
         .Include(x => x.Empresa)
         .Include(x => x.PessoasSituacoesAnalises)
         //.ThenInclude(x=> x.PessoaSituacaoTipo)
         .Load();

         return pessoa;

 }

inserir a descrição da imagem aqui

  • It’s hard to understand your objects.

  • I updated the @Edney post with part of the class diagram. I’m using EF Core 2.1 and I’m getting a get in the repository. I am including some tables, but in particular, the table "Personal Situacaoanalise", needs to be sorted downwards by date and time using the field Datascheduleanalyze.

  • 1

    It seems that the problem is to sort within Include. Try to do the query without ordering, call . Tolist() and sort the list.

  • As Edney commented, you are ordering only your include, not the full result of the query. But the class relation is confused, present to its entities (the code, not the drawing). [MCVE]

  • @Masterjr Managed to solve or quit?

  • I left it paused, but I haven’t solved @Leandro Angelo.

Show 1 more comment
No answers

Browser other questions tagged

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