Sas*_*aei 3 f# for-loop query-expressions
无论出于何种原因,我都不能在查询表达式中使用"for"构造.我得到的是以下错误.代码我正是我以前选择的工作 - >"错误:只有在计算表达式构建器定义'For'方法时才可以使用此控件构造"
#r "System.Data.Linq.dll"
#r "FSharp.Data.TypeProviders.dll"
open FSharp.Linq
open FSharp.Data.TypeProviders
[<Literal>]
let connectionString' = @"
data source = ...;
initial catalog = NORTHWND;
Integrated Security = SSPI"
type NorthwndDb =
SqlDataConnection<connectionString', Pluralize = true>
let db' = NorthwndDb.GetDataContext()
let curstomerSortedByCountry =
query { for c in db'.Customers do
sortBy c.Country
select (c.Country, c.CompanyName) }
|> Seq.cache
Run Code Online (Sandbox Code Playgroud)
我无法使用您的代码片段对此进行测试(没有数据库来测试它),但我认为如果您query在query表达式之前在代码片段中定义了一个名为somewhere 的变量,那么您所报告的错误就会发生.例如:
let query = "oops!"
let curstomerSortedByCountry =
query { for c in [1 .. 10] do
sortBy c
select c }
Run Code Online (Sandbox Code Playgroud)
错误FS0708:仅当计算表达式构建器定义"For"方法时,才可以使用此控件构造
这样做的原因是标识符queryin query { .. }只是在标准F#库中声明的变量,其中包含各种成员query.For.如果您使用自己的声明隐藏此内容,则无法找到该成员.
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |