linq - F# Query Expression using join & groupBy in same query -


i decided learn how use query expressions in f# , found the official microsoft documentation. caveats don't seem spelled out i'm sure i've hit problem simple fix don't know why i'm getting error shows.

my thought write query did both join , grouping in same go. example, using sample 'mydatabase' thought try find number of classes each student enrolled in. after writing following query, compiler flags no warning, when go run it gives error.

my query expression:

query {     student in db.student     join course in db.courseselection         on (student.studentid = course.studentid)      groupby student group      select (group.key, group.count())  }  |> seq.iter (fun (student, classcount) -> printfn "student %s has %i classes" student.name classcount) 

the error:

system.invalidoperationexception: not format node 'new' execution sql.    @ system.data.linq.sqlclient.sqlformatter.visitor.visitnew(sqlnew sox)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node) >    @ system.data.linq.sqlclient.sqlformatter.visitor.visitalias(sqlalias alias)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlformatter.visitor.visitselect(sqlselect ss)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlformatter.visitor.visitscalarsubselect(sqlsubselect ss)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlformatter.visitor.visitrow(sqlrow row)    @ system.data.linq.sqlclient.sqlformatter.visitor.visitselect(sqlselect ss)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlformatter.visitor.format(sqlnode node, boolean isdebug)    @ system.data.linq.sqlclient.sqlformatter.format(sqlnode node)    @ system.data.linq.sqlclient.sqlprovider.buildquery(resultshape resultshape, type resulttype, sqlnode node, readonlycollection`1 parentparameters, sqlnodeannotations annotations)    @ system.data.linq.sqlclient.sqlprovider.buildquery(expression query, sqlnodeannotations annotations)    @ system.data.linq.sqlclient.sqlprovider.system.data.linq.provider.iprovider.execute(expression query)    @ system.data.linq.dataquery`1.system.collections.generic.ienumerable<t>.getenumerator()    @ system.linq.enumerable.whereselectenumerableiterator`2.movenext()    @ microsoft.fsharp.collections.seqmodule.iterate[t](fsharpfunc`2 action, ienumerable`1 source)    @ <startupcode$fsi_0008>.$fsi_0008.main@() in c:\users\jdks\library\query expressions.fsx:line 129 stopped due error 

i thought out of issue using subquery:

query {     student in db.student     join course in db.courseselection         on (student.studentid = course.studentid)      let count = query {         s in student.name         select course.courseid         count     }      select (student.name, count)  }  |> seq.iter (fun (student, classcount) -> printfn "student %s has %i classes" student classcount) 

but gave larger error:

> system.notsupportedexception: sequence operators not supported type 'system.string'.    @ system.data.linq.sqlclient.sqlbinder.visitor.converttofetchedsequence(sqlnode node)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitalias(sqlalias a)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlvisitor.visitsource(sqlsource source)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitselect(sqlselect select)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitalias(sqlalias a)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlvisitor.visitsource(sqlsource source)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitselect(sqlselect select)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitalias(sqlalias a)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlvisitor.visitsource(sqlsource source)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitselect(sqlselect select)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlvisitor.visitsequence(sqlselect sel)    @ system.data.linq.sqlclient.sqlvisitor.visitscalarsubselect(sqlsubselect ss)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitsubselect(sqlsubselect ss)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitexpression(sqlexpression expr)    @ system.data.linq.sqlclient.sqlbinder.visitor.fetchexpression(sqlexpression expr)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitnew(sqlnew sox)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitexpression(sqlexpression expr)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitselect(sqlselect select)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitalias(sqlalias a)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlvisitor.visitsource(sqlsource source)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitselect(sqlselect select)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlbinder.visitor.visitincludescope(sqlincludescope scope)    @ system.data.linq.sqlclient.sqlvisitor.visit(sqlnode node)    @ system.data.linq.sqlclient.sqlbinder.bind(sqlnode node)    @ system.data.linq.sqlclient.sqlprovider.buildquery(resultshape resultshape, type resulttype, sqlnode node, readonlycollection`1 parentparameters, sqlnodeannotations annotations)    @ system.data.linq.sqlclient.sqlprovider.buildquery(expression query, sqlnodeannotations annotations)    @ system.data.linq.sqlclient.sqlprovider.system.data.linq.provider.iprovider.execute(expression query)    @ system.data.linq.dataquery`1.system.collections.generic.ienumerable<t>.getenumerator()    @ system.linq.enumerable.whereselectenumerableiterator`2.movenext()    @ microsoft.fsharp.collections.seqmodule.iterate[t](fsharpfunc`2 action, ienumerable`1 source)    @ <startupcode$fsi_0015>.$fsi_0015.main@() in c:\users\jdks\library\query expressions.fsx:line 144 stopped due error 

my guess don't understand what's going on under hood enough work out error or lead myself solution. possible query want here? there workaround?

when tried running locally got exception

system.exception: grouping on multiple tables not supported yet 

i not sure why getting less pretty version of error. if pull groupby out of query, things seem work fine.

query {     student in db.student     join course in db.courseselection         on (student.studentid = course.studentid)     select (student.name, course.id) }  |> seq.countby snd |> seq.iter (fun (student, classcount) -> printfn "student %s has %i classes" student classcount) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -