groupby multiple columns in a F# 3.0 query

前端 未结 8 834
梦如初夏
梦如初夏 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:48
    //in F# 3.0
    open Microsoft.FSharp.Linq.RuntimeHelpers
    open Microsoft.FSharp.Linq.RuntimeHelpers.LeafExpressionConverter
    open System.Linq
    
    //[<CLIMutable>]
    //type MyRecord = { Column1 : int; Column2 : int }
    // require constructor in F#
    // groupBy is not valid
    
    type T(column1 : int, column2 : int)
        member val Colum1=colum1 with get,set
        membre val Colum2=colum2 with get,set
    
    query {
        for d in context.table do
        groupValBy d (NewAnonymousObjectHelper(T(d.Colum1,d.Colume2))) into g
        select (g.Key)
        }
    
    0 讨论(0)
  • 2020-12-14 00:50

    When using groupBy you need to select an aggregating function (e.g. count, sum, avg...).

    0 讨论(0)
提交回复
热议问题