处理 GroupBy 和 Having
#r @"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.Linq.dll";;
#r @"E:\Projects\F#3\FSharp.Data.TypeProviders.dll";;
open Microsoft.FSharp.Data.TypeProviders;;
open System.Linq;;
// Count()、DefaultIfEmpty 在其中
//open System.Data.Linq;;
//open System.Data.Linq.SqlClient;
// SqlMethods 作其中
[<Generate>]
type T0 = SqlDataConnection<"Data Source=.\SQLEXPRESS;Initial Catalog=FSharpSample;User ID=sa;Password=FSharpSample1234">
let TypeProvider14() =
let db = T0.GetDataContext();
let q = query {
for s in db.Student do
groupBy s.Age into g
where (g.Count()>1)
select (g.Key, g.Count())
}
q |> Seq.iter (fun (key, count) -> printfn "Key=%A Count=%d" key count)
q |> Seq.length
//Key=<null> Count=1
//Key=20 Count=2
//Key=21 Count=2
//Key=22 Count=3
//Key=23 Count=1