F # groupBy - System.Exception: invoking an unrecognized method

I'm trying to query data using F # SqlDataProvider, but I got a weird error when I wanted to use the groupBy function

my initialization code:

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

my request:

 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) 

I got this error:

System. @ 1735-1.Microsoft-FSharp-Linq-ForwardDeclarations-IQueryMethods-Executea, b. $ FSI_0003.main @ () in C: \ Development \ CountriesParser \ Script1.fsx: line 36

Line 36 is the exact line of the By group.

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

+5
source share
1 answer

There are several different SQL type providers for F #, and I think your code uses a community-driven one that does not currently support the groupBy construct.

  • The SqlDataProvider type comes from the SQLProvider package and is documented here .
  • The FSharp.Data.TypeProviders library (also distributed through Visual Studio) is documented here and provides the SqlDataConnection type.
  • You also mentioned that the ComposableQuery library is documented here , which is an extension that you can use on top of (2), but you are not doing this in your code.

Library (1) is more convenient in several ways, but does not yet support the full query language, so you may have to switch to (2).

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

+2
source

Source: https://habr.com/ru/post/1247942/


All Articles