TypeProvider query CASE

Category:
TypeProviders.SqlDataConnection
Description: type provider sample: CASE. Use the CreateFSharpSampleDatabase.sql to setup your database tables.
Code:

type T0 = Microsoft.FSharp.Data.TypeProviders.SqlDataConnection< "Data Source=localhost;Initial Catalog=FSharpSample;User ID=sa;Password=FSharpSample1234" >

let TypeProvider13() =
let db = T0.GetDataContext();
let q = query {
for n in db.Student do
select (if n.Age.HasValue && n.Age.Value=1 then (n.StudentID, System.Nullable(n.Age.Value*100), n.Age) else (n.StudentID, n.Age, n.Age))
}
q |> Seq.iter (fun n -> printfn "%A" n)
Assert.AreEqual(q |> Seq.length, 9)

Execution Result:
(1, 21, 21)
(2, 22, 22)
(3, 20, 20)
(4, 22, 22)
(5, 22, 22)
(6, 20, 20)
(7, 21, 21)
(8, 23, 23)
(9, null, null)
both elements are equal

Last edited Mar 1, 2012 at 8:03 PM by ttliu2000, version 2

Comments

No comments yet.