groupby multiple columns in a F# 3.0 query

前端 未结 8 847
梦如初夏
梦如初夏 2020-12-14 00:02

Just trying out F# 3.0 and hit a bit of a wall when it comes to grouping by multiple columns. The obvious thing to try was

query {
    for d in context.table         


        
8条回答
  •  半阙折子戏
    2020-12-14 00:23

    First you have to remember that a query is translated into actual SQL at some point. It appears that linq does not support the use of multiple group keys as a Tuple<>. Therefore any transformation into Tuple<> has to be done after the database call has completed.

    Second, you should be able to achieve multiple key grouping by performing multiple groupings behind each other on the respective keys:

    query {
        for d1 in context.table do
        groupBy d1.col1 into g1
        for d2 in g1 do
        groupBy d2.col2 into g2
        select g2
    }
    

    Please have mercy with me if the syntax is not 100% since F# is not my native tongue :) The concept however should work just fine.

提交回复
热议问题