Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
i want to write linq query or lambda expresion fot this sql query
SQL
select Max(tblEmailList.name),count(tblEmailRecipientList.ListId) from tblEmailList  join tblEmailRecipientList on tblEmailRecipientList.ListId = tblEmailList.ListId
group by tblEmailRecipientList.ListId


thanks in advance
Posted
Comments
Sinisa Hajnal 13-Oct-15 4:52am    
What have you tried? Also, what is wrong with using SQL query?
Anil Sharma1983 13-Oct-15 5:50am    
in this way we achieve result in linq lamda expression. for this example i have made
the dummy list (tblEmailList and tblEmailRecipientList)


var result = _tblEmailList.AsEnumerable()
.Join(_tblEmailRecipientList.AsEnumerable(), o => o.ListId, od => od.ListId,
(o, od) => new { _tblEmailList = o, rList = od })
.GroupBy(p => p.rList.ListId).Select(g => new
{
count = g.Count(),
MaxName = g.Max(p => p._tblEmailList.name)

});

Try like below:
C#
var result = from p in context.tblEmailRecipientList             
 join c in context.tblEmailList on p.ListId equals c.ListId  
 group p by p.ListId into temp 
 select new 
 {
       TotalCount = temp.Count(), 
       MaxName = temp.Max(m => m.name)
 };
 
Share this answer
 
Comments
Maciej Los 13-Oct-15 11:01am    
Looks good, +5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900