Aggregate table using linq to entities

2019-08-31 20:11发布

I've a table like this

Id  MachineName ServerName  TagName TagValue    ValueDateTime
1   DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.STR02_METER_DENSITY_(1)  93.1631400000   2018-06-04 21:08:28.720
2   DanPac_A    Daniel.Device Links.1   Diagnostics.Heartbeat   1.0000000000    2018-06-04 21:08:32.717
3   DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873
4   DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873
5   DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
6   DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
7   DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
8   DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
9   DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873
10  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
11  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873
12  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
13  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873
14  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
15  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
16  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873
17  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(7)   16.8916200000   2018-06-04 21:08:32.873
18  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873
19  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873
20  DanPac_A    Daniel.Device Links.1   Poll.Registers Block 0.310-TT-302_(6)   52.1062000000   2018-06-04 21:08:32.873

Data is getting logged into server in 24 hrs time format with 5 sec interval, and I need to aggregate this into hourly, weekly, daily, minute basis based on interval choose by user.

I could gate interval by datediff, my query is how can I aggregate this table into any above format using linq to entities query.

e.g. If user select date rage from 6-jun-2018 : 09:24:111 to 7-jun-2018 : 09:25:00 so query should return

"MachineName, ServerName, TagName, TagValue (average for that hour), ValueDateTime (hourly i.e. 6-jun-2018:09:24, 6-jun-2018:10:24 .. )

Any help ..

0条回答
登录 后发表回答