如何将此 Sql 查询转换为 LINQ?
我想将下面的查询转换为 LINQ,
SELECT AVG(currentvalue) AS ChartAvg,
CONVERT(varchar(10), ReceivedDate, 103) AS RecDate
FROM DatapointValues
WHERE (CONVERT(varchar(10), ReceivedDate, 103) = '21/04/2011')
GROUP BY CONVERT(varchar(10), ReceivedDate, 103)
我使用下面的 LINQ 但不起作用,
from datapointvalues in db.DatapointValues
where
Convert.ToString(datapointvalues.ReceivedDate) == "21/04/2011"
group datapointvalues by new {
Column1 = Convert.ToString(datapointvalues.ReceivedDate)
} into g
select new {
ChartAvg = (System.Decimal?)g.Average(p => p.currentvalue),
g.Key.Column1
}
I want to convert the below query to LINQ,
SELECT AVG(currentvalue) AS ChartAvg,
CONVERT(varchar(10), ReceivedDate, 103) AS RecDate
FROM DatapointValues
WHERE (CONVERT(varchar(10), ReceivedDate, 103) = '21/04/2011')
GROUP BY CONVERT(varchar(10), ReceivedDate, 103)
I use the below LINQ but not working,
from datapointvalues in db.DatapointValues
where
Convert.ToString(datapointvalues.ReceivedDate) == "21/04/2011"
group datapointvalues by new {
Column1 = Convert.ToString(datapointvalues.ReceivedDate)
} into g
select new {
ChartAvg = (System.Decimal?)g.Average(p => p.currentvalue),
g.Key.Column1
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看这篇文章:http://msdn.microsoft.com/en-us/库/bb882657.aspx
Check out this article: http://msdn.microsoft.com/en-us/library/bb882657.aspx