F#groupBy-System.Exception:无法识别的方法调用 [英] F# groupBy - System.Exception : unrecognized method call

查看:33
本文介绍了F#groupBy-System.Exception:无法识别的方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用F#SqlDataProvider查询数据,但是当我想使用groupBy函数时遇到了奇怪的错误

I'm trying to query data with F# SqlDataProvider but I got strange error when I'd like to use groupBy function

我的初始化代码:

r# "packages/FSharp.Data.2.2.5/lib/net40/FSharp.Data.dll"
r# "packages/SQLProvider.1.0.0/lib/FSharp.Data.SQLProvider.dll"
r# "packages/FSharp.Data.TypeProviders.5.0.0.2/lib/net40/FSharp.Data.TypeProviders.dll"

open FSharp.Data
open FSharp.Data.Sql
open FSharp.Data.TypeProviders
open FSharp.Linq
open System.Text.RegularExpressions
open System
open System.Data

type dbSchema = SqlDataProvider<
                    ConnectionString = "my-connection-string",
                    DatabaseVendor = Common.DatabaseProviderTypes.MSSQLSERVER,
                    IndividualsAmount = 1000,
                    UseOptionTypes = true>
let db = dbSchema.GetDataContext()

我的查询:

query {
    for county in db.Dbo.Countries do
    groupBy county.CountryCode into g
    select (g.Key, g.Count())
    } |> Seq.iter (fun (key, count) -> printfn "%s %d" key count)

我收到此错误:

System.Exception:无法识别的方法调用在Microsoft.FSharp.Linq.RuntimeHelpers.LeafExpressionConverter.EvaluateQuotation(FSharpExpr e)在Microsoft.FSharp.Linq.QueryModule.EvalNonNestedInner(CanEliminate canElim,FSharpExpr queryProducingSequence)在Microsoft.FSharp.Linq.QueryModule.clo @ 1735-1.Microsoft-FSharp-Linq-ForwardDeclarations-IQueryMethods-Executea,b在.$ FSI_0003.main @()在C:\ Development \ CountriesParser \ Script1.fsx:第36行

System.Exception: unrecognised method call at Microsoft.FSharp.Linq.RuntimeHelpers.LeafExpressionConverter.EvaluateQuotation(FSharpExpr e) at Microsoft.FSharp.Linq.QueryModule.EvalNonNestedInner(CanEliminate canElim, FSharpExpr queryProducingSequence) at Microsoft.FSharp.Linq.QueryModule.clo@1735-1.Microsoft-FSharp-Linq-ForwardDeclarations-IQueryMethods-Executea,b at .$FSI_0003.main@() in C:\Development\CountriesParser\Script1.fsx:line 36

第36行是groupBy的确切行.

The line 36 is exact line of groupBy.

当我在这些页面中阅读时,它应该可以工作 http://fsprojects.github.io/FSharp.Linq.ComposableQuery/QueryExamples.html https://msdn.microsoft.com/en-us/library/hh225374.aspx

As I read in these pages, it should work http://fsprojects.github.io/FSharp.Linq.ComposableQuery/QueryExamples.html https://msdn.microsoft.com/en-us/library/hh225374.aspx

推荐答案

F#有许多不同的SQL类型提供程序,我认为您的代码使用社区驱动的不支持 groupBy 现在构建.

There is a number of different SQL type providers for F# and I think your code uses community-driven one that does not support the groupBy construct at the moment.

  1. 类型 SqlDataProvider 来自 SQLProvider 包,并已记录在这里.
  2. FSharp.Data.TypeProviders 库(也随Visual Studio一起分发)在此处中记录的ComposableQuery库.在(2)之上使用,但您并未在代码中这样做.
  1. The type SqlDataProvider comes from SQLProvider package and is documented here.
  2. The FSharp.Data.TypeProviders library (also distributed with Visual Studio) is documented here and exposes SqlDataConnection type.
  3. You also mentioned ComposableQuery library documented here, which is an extension that you can use on top of (2), but you're not doing that in your code.

库(1)在许多方面都比较好,但是还不支持完整的查询语言,因此您可能需要切换到(2).

The library (1) is nicer in a number of ways, but does not support the full query language yet, so you'll probably need to switch to (2).

为此,请仅引用 FSharp.Data.TypeProviders (您不需要其他两个包),然后在SqlDataConnection 类型="https://msdn.microsoft.com/en-us/library/hh361033.aspx" rel ="nofollow">有关该主题的MSDN演练

To do that, reference just FSharp.Data.TypeProviders (you do not need the other two packages) and then use the SqlDataConnection type, following the MSDN Walkthrough on the topic

这篇关于F#groupBy-System.Exception:无法识别的方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆