LINQ查询帮助!

时间:2010-05-12 16:52:48

标签: linq linq-to-sql linq-to-entities

有人可以帮我将以下SQL查询转换为LINQ吗?

select
    convert(varchar(10),date,110) as 'Date',
    max(users) as 'Maximum Number of Users', 
    max(transactions) as 'Maximum Number of Transactions'
from
    stats
where
    datepart(Year, Date) = '2010'
group by
    convert(varchar(10),date,110) 
order by
    convert(varchar(10),date,110)

提前谢谢!

1 个答案:

答案 0 :(得分:0)

很难从您提供的有限信息中辨别出来,但这可能会起到作用:

var results = from stat in db.Stats
              group stat by stat.Date.Date into statGroup
              orderby statGroup.Key
              select new
              {
                Date = statGroup.Key,
                MaximumNumberOfUsers = statGroup.Max(c => c.Users),
                MaximumNumberOfTransactions = statGroup.Max(c => c.Transactions)
              };