简体   繁体   中英

lambda expression join multiple tables ASP.NET MVC 5

How can I transform this SQL into a lambda expression?

SELECT datename(month,eve.EVNfechainicio) AS mes,
       count(eve.EVNid_evento) AS 'Cantidad de Eventos'
FROM pubEVNtEvento AS eve
INNER JOIN pubEMPtEmpresa AS emp ON eve.EMPid_empresa= emp.EMPid_empresa
WHERE emp.EMPnombre='TecnoEventos'
  AND year(eve.EVNfechainicio)= '2016'
GROUP BY datename(month,eve.EVNfechainicio)

I think the lambda Expression should be for the above sql query is

db.pubEVNtEvento.Include(i=> i.pubEMPtEmpresa )
        .Where(r => r.pubEMPtEmpresa.EMPnombre=='TecnoEventos' &&
    r.EVNfechainicio=='2016').GroupBy(p=> p.EVNfechainicio).ToList();

Here db is the instance of your Entity framework DbContext

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM