LINQ to SQL 查询结果不一样 我哪里写错了?

SomethingJack 2016-01-08 03:54:27
SQL查询结果是96条数据 LINQ只有一条.请各位帮忙看看 谢谢 liqn用的少

SQL

SELECT MeasureLine ,
LaneNum ,
CarType ,
SUM(Av_speeddata) ,
SUM(Vloume) ,
SUM(occuancy)
FROM dbo.Table_1
WHERE MeasureLine IN ( 0, 1, 2, 3 )
GROUP BY MeasureLine ,
LaneNum ,
CarType
ORDER BY MeasureLine



LINQ

List<tagStaRecordStruct> matchesRadarData =
(from x in list
//where lineFilter.Contains(x.MeasureLine)
group x by new { x.MeasureLine, x.LaneNum, x.CarType }
into temp
orderby temp.Key.MeasureLine
select new tagStaRecordStruct()
{
MeasureLine = temp.First().MeasureLine,
LaneNum = temp.First().LaneNum,
CarType = temp.First().CarType,
Vloume = temp.Sum(y => y.Vloume),
Av_speeddata = temp.Sum(y => y.Av_speeddata),
Occuancy = temp.Sum(y => y.Occuancy)
}).ToList();
...全文
121 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SomethingJack 2016-01-08
  • 打赏
  • 举报
回复
引用 3 楼 starfd 的回复:
看起来没问题,确认你的list数据和数据库的是一样的吗?
数据肯定是一样的 没错的.奇怪的很 我在调试
  • 打赏
  • 举报
回复
看起来没问题,确认你的list数据和数据库的是一样的吗?
SomethingJack 2016-01-08
  • 打赏
  • 举报
回复
引用 1 楼 starfd 的回复:
用Key获取Group,不是First
List<tagStaRecordStruct> matchesRadarData =
    (from x in list
         //where lineFilter.Contains(x.MeasureLine)
     group x by new { x.MeasureLine, x.LaneNum, x.CarType }
     into temp
     orderby temp.Key.MeasureLine
     select new tagStaRecordStruct()
     {
        MeasureLine = temp.Key.MeasureLine,
        LaneNum = temp.Key.LaneNum,
        CarType = temp.Key.CarType,
        Vloume = temp.Sum(y => y.Vloume),
        Av_speeddata = temp.Sum(y => y.Av_speeddata),
        Occuancy = temp.Sum(y => y.Occuancy)
     }).ToList();
谢谢回复 是这样的 我刚才测试过key.属性 也是一条数据 很奇怪。 语法什么的都没有问题吧?
  • 打赏
  • 举报
回复
用Key获取Group,不是First
List<tagStaRecordStruct> matchesRadarData =
    (from x in list
         //where lineFilter.Contains(x.MeasureLine)
     group x by new { x.MeasureLine, x.LaneNum, x.CarType }
     into temp
     orderby temp.Key.MeasureLine
     select new tagStaRecordStruct()
     {
        MeasureLine = temp.Key.MeasureLine,
        LaneNum = temp.Key.LaneNum,
        CarType = temp.Key.CarType,
        Vloume = temp.Sum(y => y.Vloume),
        Av_speeddata = temp.Sum(y => y.Av_speeddata),
        Occuancy = temp.Sum(y => y.Occuancy)
     }).ToList();

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧