How to pass the type generated by F#'s SqlDataProvider as a parameter to function

326 views Asked by At

I'm try to write a tool that compares two db using F#'s SqlDataProvider as the data access. This means excuting the same query on two different databases. The would be easy, if I could pass the data content to a function as a parameter, however, because the data context is a generated type is doesn't seem to have proper name, so I'm unable to pass it as a parameter.

Here an example of what I'd like to able to do:

type MyDb = SqlDataProvider< 
              @"Server=myServerDatabase=myDatabase;Trusted_Connection=True;",
              Common.DatabaseProviderTypes.MSSQLSERVER>


let ctx1 = RfqDb.GetDataContext("Server=myServerDatabase=myDatabase;Trusted_Connection=True;")
let ctx2 = RfqDb.GetDataContext("Server=myServerDatabase=myOtherDatabase;Trusted_Connection=True;")


let getGetData (ctx: ...) = // don't know what to put for ...
    query { for ue in ctx.``[dbo].[MyTable]`` do
            where (ue.UnderlyingID = "MyId")} 
    |> Seq.toArray


let grid1 = new EntityViewGrid()
let grid2 = new EntityViewGrid()
grid1.ItemsSource <- getGetData  ctx1
grid2.ItemsSource <- getGetData  ctx2

It's the line with the // don't know what to put for ... comment that's giving me problems.

1

There are 1 answers

0
Robert On

Just figured it out, simpler than I thought, just the VS tooltips are a bit misleading. The correct sample looks like:

type MyDb = SqlDataProvider< 
              @"Server=myServerDatabase=myDatabase;Trusted_Connection=True;",
              Common.DatabaseProviderTypes.MSSQLSERVER>


let ctx1 = RfqDb.GetDataContext("Server=myServerDatabase=myDatabase;Trusted_Connection=True;")
let ctx2 = RfqDb.GetDataContext("Server=myServerDatabase=myOtherDatabase;Trusted_Connection=True;")


let getGetData (ctx: MyDb.dataContext) = 
    query { for ue in ctx.``[dbo].[MyTable]`` do
            where (ue.UnderlyingID = "MyId")} 
    |> Seq.toArray


let grid1 = new EntityViewGrid()
let grid2 = new EntityViewGrid()
grid1.ItemsSource <- getGetData  ctx1
grid2.ItemsSource <- getGetData  ctx2