我有一个答案列表,我通过匹配FormId然后匹配ProductInstance和最后一个TimeStamp来分组:
var groups = answersForCustomerList.GroupBy(x => new { x.FormId, x.ProductInstance, x.TracingData.Timestamp });
给了我这样的团体:
FormId = {97748e5e-be41-4d53-9ef8-f0dc150e58b6}, ProductInstance = "kontot", Timestamp = {2016-12-20 16:00:00}
FormId = {87dd356b-2770-4427-89d2-7503ee80bb1c}, ProductInstance = "Lån", Timestamp = {2016-12-20 16:02:00}
FormId = {87dd356b-2770-4427-89d2-7503ee80bb1c}, ProductInstance = "Lån", Timestamp = {2016-12-20 16:01:00}
FormId = {97748e5e-be41-4d53-9ef8-f0dc150e58b6}, ProductInstance = "Konto", Timestamp = {2016-12-20 15:00:00}
FormId = {87dd356b-2770-4427-89d2-7503ee80bb1c}, ProductInstance = "Lån", Timestamp = {2016-12-20 15:59:00}
但我需要做什么似乎无法计算如何将+/- 1分钟内的时间戳分组到同一组中。所以使用相同的FormId和ProductInstance但使用TimeStamp 16:01:00或15:59:00的答案与16:00:00组在同一组中。
答案 0 :(得分:0)
我设法得到了我想要的东西:
var groups = answersForCustomer
.GroupBy(x =>
{
var stamp = x.TracingData.Timestamp;
stamp = stamp.AddMinutes(-(stamp.Minute % 2));
stamp = stamp.AddMilliseconds(-stamp.Millisecond - 1000 * stamp.Second);
return new { stamp, x.FormId, x.ProductInstance };
});
这给了我的团队提前2分钟,感谢所有答案!