我尝试编写一个工具,使用F#' s SqlDataProvider作为数据访问来比较两个数据库。这意味着在两个不同的数据库上排除相同的查询。如果我可以将数据内容作为参数传递给函数,那将很容易,因为数据上下文是生成的类型似乎没有正确的名称,所以我无法通过它作为参数。
以下是我希望能够做到的一个例子:
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
// don't know what to put for ...
评论中的一行给我带来了问题。
答案 0 :(得分:0)
刚想通了,比我想象的简单,只是VS工具提示有点误导。正确的样本如下:
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