Linq isn't specific to C#. Even in C# you need to add a reference to System.Linq.dll
and a using System.Linq;
statement. The C# project templates already include these statements.
In F# you need to do the same, ensure your project has a reference to System.Linq and add an open System.Linq
statement
There are at least two more idiomatic ways:
You can use the Seq module's functions with the pipeline operator achieve the same result as method chaining, eg:
let random = new System.Random()
Seq.initInfinite (fun _ -> random.Next())
|> Seq.filter (fun x -> x % 2 = 0)
|> Seq.take 5
|> Seq.iter (fun elem -> printf "%d " elem)
printfn ""
seq<'T>
is a synonym of IEnumerable<T>
so if you apply the methods to an IQueryable it will force the query's execution.
You can use Query Expressions, equivalent to LINQ's SQL-like syntax:
let countOfStudents =
query {
for student in db.Student do
select student
count
}
query
returns a proper IQueryable<T>
Your specific query could be something like this:
let database =
query {
for db in client.CreateDatabaseQuery()
where db.Id == "FamilyRegistry"
select db
headOrDefault
}
System.Linq
? LINQ isn't C# specific. Even in C# you need to add a reference toSystem.Linq.dll
and ausing System.Linq;
statement – Panagiotis Kanavos Dec 16 '14 at 15:02.ToArray()
call in the C# code? Does that serve an actual purpose, or is it just there to waste time? – Joel Mueller Dec 16 '14 at 17:23