Bring the last five in a row

Asked

Viewed 1,703 times

-3

I have a table of events. And each POS, an event is held, with the Event ID, Date, User and Type. Well, whenever I make a query, I populate an event grid. I would like to know, how to bring the last five with LINQ and/or Lambda, to the same CNPJ?

Is that code correct?

var result_evento = (from ev in db.T_CRM_Evento
                                 select new { ev.ID_CRM_Evento, ev.DE_Usuario, ev.ID_TipoEvento, ev.DT_Inclusao})
                                 .Take(5)
                                 .Max(evento => evento.DT_Inclusao);

This one worked. It messed with my layout, but it worked. At least in terms of bank result, it worked.

 var result_evento = (from ev in db.T_CRM_Evento
                         .Where(e => e.DE_CNPJ == carregagrid.Cnpj)
                                     select new { ev.ID_CRM_Evento, ev.DE_Usuario, ev.ID_TipoEvento, ev.DT_Inclusao })
                                     .Take(5)
                                     .OrderByDescending(dt => dt.DT_Inclusao);

1 answer

2


I’m finding it very strange that the above one didn’t work, anyway, do it

var result_evento = (from ev in db.T_CRM_Evento
                         where ev.DE_CNPJ == carregagrid.Cnpj
                         select new {
                            ev.ID_CRM_Evento, 
                            ev.DE_Usuario, 
                            ev.ID_TipoEvento, 
                            ev.DT_Inclusao 
                         }).Take(5).OrderByDescending(dt => dt.DT_Inclusao);

I really hope that it worked, because according to your descriptions, this code just, if possible, send your view or where you are showing the results, maybe it is elsewhere the problem.

  • But I already did. As I said, it has been solved.

  • Oops, so sorry :X - Good luck with the project.

  • 1

    Thanks man, as your answer was the same as mine and for no equal answer, I will mark yours with valid.

  • The question seems to have already been answered so I leave a hint : When you have a question with Linqer I suggest to use, it converts SQL to LINQ. Very useful. If you have Reshaper he can suggest a lambda for you.

Browser other questions tagged

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