我正在关注一本关于查询表达式的书中的示例。我没有完全按照书中的内容输入,令我惊讶的是,即使对于 F# 中的内部连接查询,序列的顺序也很重要。这本书根本没有提到任何关于订单的内容,msdn只说订单很重要。但是为什么即使对于内部连接也很重要?
这不编译,它说namespace or module fa is not defined
;相同的f
:
query { for f in QuerySource.films do
join fa in QuerySource.filmActors on (fa.FilmId = f.Id)
join a in QuerySource.actors on (fa.ActorId = a.Id)
select (f.Name, f.ReleaseYear, a.LastName, a.FirstName)
}
但这确实:
query { for f in QuerySource.films do
join fa in QuerySource.filmActors on (f.Id = fa.FilmId)
join a in QuerySource.actors on (fa.ActorId = a.Id)
select (f.Name, f.ReleaseYear, a.LastName, a.FirstName)
}
EDIT1:不要认为这很重要,但为了澄清,这里是QuerySource
模块
module QuerySource =
open System
type Film = {Id : int; Name: string; ReleaseYear : int; Gross : Nullable<float>}
override x.ToString() = sprintf "%s (%i)" x.Name x.ReleaseYear
type Actor = {Id : int; FirstName : string; LastName : string}
override x.ToString() = sprintf "%s %s" x.LastName x.FirstName
type FilmActor = {FilmId : int; ActorId : int}
let films =
[ {Id = 1; Name = "The Terminator"; ReleaseYear = 1984; Gross = Nullable 38400000.0}
{Id = 2; Name = "Predator"; ReleaseYear = 1987; Gross = Nullable 59735548.0}
{Id = 3; Name = "Commando"; ReleaseYear = 1985; Gross = Nullable 38122105.0}
{Id = 4; Name = "The Running Man"; ReleaseYear = 1987; Gross = Nullable<float>()}
{Id = 5; Name = "Conan the Destroyer"; ReleaseYear = 1984; Gross = Nullable<float>()}
]
let actors = [{Id = 1; FirstName = "Arnold"; LastName = "Schwarzenegger"}
{Id = 2; FirstName = "Linda"; LastName = "Hamilton"}
{Id = 3; FirstName = "Carl"; LastName = "Weathers"}
{Id = 4; FirstName = "Jesse"; LastName = "Ventura"}
{Id = 5; FirstName = "Vernon"; LastName = "Wells"}
]
let filmActors =
[ {FilmId = 1; ActorId = 1}
{FilmId = 1; ActorId = 2}
{FilmId = 2; ActorId = 1}
{FilmId = 2; ActorId = 3}
{FilmId = 2; ActorId = 4}
{FilmId = 3; ActorId = 1}
{FilmId = 3; ActorId = 5}
{FilmId = 4; ActorId = 1}
{FilmId = 4; ActorId = 4} // internationally omitted for filmid = 5
]`