在下面的代码中,我尝试返回一个新的序列类型,该序列类型由原始序列中的ProductName,Size和Packaging属性分组,但我得到一个未分组的新类型序列。我在这里缺少什么?
query{
for row in allDeliveries do
let key = AnonymousObject<_,_,_>(row.ProductName,row.Size,row.Packaging)
groupValBy row key into g
select g
}
|> Seq.map (fun (del) ->
{
POFD = del;
ProductName = del.Key.Item1;
Size = del.Key.Item2;
Packaging = del.Key.Item3;
Quantity = del.Count()
})
答案 0 :(得分:2)
这是我的解决方案:
query{
for row in allDeliveries do
groupValBy row (row.ProductName, row.Size, row.Packaging) into g
select {
POFD = g;
ProductName = query{
for row2 in g do
select row2.ProductName
headOrDefault
}
Size = query{
for row2 in g do
select row2.Size
headOrDefault
}
Packaging = query{
for row2 in g do
select row2.Packaging
headOrDefault
}
Quantity = g.Count()
}
}