Grouping by multiple columns and then projecting












2















In the below code I am trying to return a new sequence type that is grouped by the ProductName, Size, and Packaging properties from the original sequence, but instead I get a new type sequence that is ungrouped. What am I missing here?



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()
})









share|improve this question




















  • 2





    I don't think that AnonymousObject will implement some kind of equivalence check - why don't you use a normal F# tuple like groupValBy row (row.ProductName, row.Size, row.Packaging)? And why don't you use the select part to get your record directly?

    – Carsten
    Aug 10 '14 at 6:32


















2















In the below code I am trying to return a new sequence type that is grouped by the ProductName, Size, and Packaging properties from the original sequence, but instead I get a new type sequence that is ungrouped. What am I missing here?



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()
})









share|improve this question




















  • 2





    I don't think that AnonymousObject will implement some kind of equivalence check - why don't you use a normal F# tuple like groupValBy row (row.ProductName, row.Size, row.Packaging)? And why don't you use the select part to get your record directly?

    – Carsten
    Aug 10 '14 at 6:32
















2












2








2








In the below code I am trying to return a new sequence type that is grouped by the ProductName, Size, and Packaging properties from the original sequence, but instead I get a new type sequence that is ungrouped. What am I missing here?



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()
})









share|improve this question
















In the below code I am trying to return a new sequence type that is grouped by the ProductName, Size, and Packaging properties from the original sequence, but instead I get a new type sequence that is ungrouped. What am I missing here?



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()
})






f# f#-3.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 5:15









Cœur

17.7k9106145




17.7k9106145










asked Aug 10 '14 at 6:18









user1206480user1206480

70811429




70811429








  • 2





    I don't think that AnonymousObject will implement some kind of equivalence check - why don't you use a normal F# tuple like groupValBy row (row.ProductName, row.Size, row.Packaging)? And why don't you use the select part to get your record directly?

    – Carsten
    Aug 10 '14 at 6:32
















  • 2





    I don't think that AnonymousObject will implement some kind of equivalence check - why don't you use a normal F# tuple like groupValBy row (row.ProductName, row.Size, row.Packaging)? And why don't you use the select part to get your record directly?

    – Carsten
    Aug 10 '14 at 6:32










2




2





I don't think that AnonymousObject will implement some kind of equivalence check - why don't you use a normal F# tuple like groupValBy row (row.ProductName, row.Size, row.Packaging)? And why don't you use the select part to get your record directly?

– Carsten
Aug 10 '14 at 6:32







I don't think that AnonymousObject will implement some kind of equivalence check - why don't you use a normal F# tuple like groupValBy row (row.ProductName, row.Size, row.Packaging)? And why don't you use the select part to get your record directly?

– Carsten
Aug 10 '14 at 6:32














1 Answer
1






active

oldest

votes


















2














This was my solution:



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()
}
}





share|improve this answer



















  • 2





    see ... tuples did it for you ;)

    – Carsten
    Aug 10 '14 at 13:37











  • @CarstenKönig yeah u should of posted it as an answer, :-)

    – user1206480
    Aug 10 '14 at 14:32






  • 1





    nah it's fine ... I hope you get some Rep if you accept your own ... have some +1 ;)

    – Carsten
    Aug 10 '14 at 14:57











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25226100%2fgrouping-by-multiple-columns-and-then-projecting%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














This was my solution:



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()
}
}





share|improve this answer



















  • 2





    see ... tuples did it for you ;)

    – Carsten
    Aug 10 '14 at 13:37











  • @CarstenKönig yeah u should of posted it as an answer, :-)

    – user1206480
    Aug 10 '14 at 14:32






  • 1





    nah it's fine ... I hope you get some Rep if you accept your own ... have some +1 ;)

    – Carsten
    Aug 10 '14 at 14:57
















2














This was my solution:



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()
}
}





share|improve this answer



















  • 2





    see ... tuples did it for you ;)

    – Carsten
    Aug 10 '14 at 13:37











  • @CarstenKönig yeah u should of posted it as an answer, :-)

    – user1206480
    Aug 10 '14 at 14:32






  • 1





    nah it's fine ... I hope you get some Rep if you accept your own ... have some +1 ;)

    – Carsten
    Aug 10 '14 at 14:57














2












2








2







This was my solution:



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()
}
}





share|improve this answer













This was my solution:



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()
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 10 '14 at 13:28









user1206480user1206480

70811429




70811429








  • 2





    see ... tuples did it for you ;)

    – Carsten
    Aug 10 '14 at 13:37











  • @CarstenKönig yeah u should of posted it as an answer, :-)

    – user1206480
    Aug 10 '14 at 14:32






  • 1





    nah it's fine ... I hope you get some Rep if you accept your own ... have some +1 ;)

    – Carsten
    Aug 10 '14 at 14:57














  • 2





    see ... tuples did it for you ;)

    – Carsten
    Aug 10 '14 at 13:37











  • @CarstenKönig yeah u should of posted it as an answer, :-)

    – user1206480
    Aug 10 '14 at 14:32






  • 1





    nah it's fine ... I hope you get some Rep if you accept your own ... have some +1 ;)

    – Carsten
    Aug 10 '14 at 14:57








2




2





see ... tuples did it for you ;)

– Carsten
Aug 10 '14 at 13:37





see ... tuples did it for you ;)

– Carsten
Aug 10 '14 at 13:37













@CarstenKönig yeah u should of posted it as an answer, :-)

– user1206480
Aug 10 '14 at 14:32





@CarstenKönig yeah u should of posted it as an answer, :-)

– user1206480
Aug 10 '14 at 14:32




1




1





nah it's fine ... I hope you get some Rep if you accept your own ... have some +1 ;)

– Carsten
Aug 10 '14 at 14:57





nah it's fine ... I hope you get some Rep if you accept your own ... have some +1 ;)

– Carsten
Aug 10 '14 at 14:57


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25226100%2fgrouping-by-multiple-columns-and-then-projecting%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Coverage of Google Street View

Full-time equivalent

Surfing