Bring the last five into a linq [closed]

-3

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

Is this 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 linq worked. Moved with my layout, but deyu sure. At least in terms of the bank's bottom line, 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);
    
asked by anonymous 27.06.2014 / 18:29

1 answer

2

I'm finding it very strange that the above linq did not work, anyway, do that

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 it worked, because according to its descriptions, this code is enough, if possible, send your view or where you are showing the results, maybe it is elsewhere the problem.

    
27.06.2014 / 19:36