如何将此成员表查询转换为linq

时间:2011-10-11 20:49:01

标签: c# .net winforms entity-framework linq-to-entities

我有一个包含

列的成员表
 member_id
 member_lastname
 member_firstname

我有另一个表格访问列

visit_id
member_id
visit_date

我有像这样的mysql查询

string sql =  @"SELECT COUNT('x') AS numVisits, member_firstname as firstname, member_lastname as lastname, members.member_id
                FROM visits, members
                WHERE visits.member_id = members.member_id
                 AND visit_Date BETWEEN @startdate AND @enddate
                GROUP BY member_firstname, member_lastname, members.member_id
                ORDER BY COUNT('x') DESC";

如何将此查询转换为linq到实体

我的实体名称是trasitdbcontext

任何人都会对此有所了解......

非常感谢......

1 个答案:

答案 0 :(得分:2)

from v in visits
join m in members on v.member_id equals m.member_id
where v.visit_Date >= startDate && v.visit_Date <= endDate
group m by new {  m.member_firstname, m.member_lastname, m.member_id } into g
orderby g.Count()
select new
{
   count = g.Count(),
   member_firstname = g.Key.member_firstname, 
   member_lastname = = g.Key.member_lastname,
   member_id = = g.Key.member_id,
}