【发布时间】:2013-04-17 22:45:35
【问题描述】:
我在 Entity Framework 中设计的实体如下所示:
事件
- EventId
- 日期
- 加速
- 强度
- 设备ID
- 区块ID
- 设备
- 阻止
阻止
- 区块ID
- 开始日期
- 日期结束
- 活动
设备
- 设备ID
- 别名
- 集群 ID
- 集群
- 活动
集群
- 集群 ID
- 姓名
- 设备
- 区域标识
地区
- 区域标识
- 姓名
- 集群
一个事件属于一个块并由一个设备注册。一个Device属于一个Cluster,一个Cluster属于一个Region。
我要做的是获取块中事件的平均加速度和平均强度,组织在列表中的对象中,这些对象必须根据我是否想获得事件的平均值来组织每个集群或每个区域中的设备检测到的块。
我应该在 LINQ 中使用哪种查询?
为了更清楚,这些是代表我要执行的操作的 SQL 字符串
select avg(e.Intensity) as average from blocks b, events e, devices d, clusters c, regions r where b.blockid = 1 and b.blockid = e.blockid and e.uniqueid= d.uniqueid and d.clusterid = c.clusterid group by c.clusterid;
select avg(e.Intensity) as average from blocks b, events e, devices d, clusters c, regions r where b.blockid = 1 and b.blockid = e.blockid and e.uniqueid= d.uniqueid and d.clusterid = c.clusterid and c.regionid = r.regionid group by c.regionid;
【问题讨论】:
标签: c# linq linq-to-sql average