如何将此 Sql 查询转换为 LINQ?

发布于 2024-11-05 09:08:03 字数 658 浏览 0 评论 0原文

我想将下面的查询转换为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残龙傲雪 2024-11-12 09:08:03

查看这篇文章:http://msdn.microsoft.com/en-us/库/bb882657.aspx

var date = DateTime.Parse("21/04/2011");

var result = from datapointvalues in db.DatapointValues
             where datapointvalues.ReceivedDate.Date.equals(date)
             group datapointvalues by datapointvalues.ReceivedDate.Date
             into g
             select new
             { 
                 ChartAvg = g.Average(p => p.currentvalue),
                 RecDate = g.Key
             };

Check out this article: http://msdn.microsoft.com/en-us/library/bb882657.aspx

var date = DateTime.Parse("21/04/2011");

var result = from datapointvalues in db.DatapointValues
             where datapointvalues.ReceivedDate.Date.equals(date)
             group datapointvalues by datapointvalues.ReceivedDate.Date
             into g
             select new
             { 
                 ChartAvg = g.Average(p => p.currentvalue),
                 RecDate = g.Key
             };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文