F # Choose from SQL Server table syntax

I have a synonym for a table in my SQL Server database.

I want to select rows from a table, but when I create a data context with a type provider, I do not see a synonym in the created data context.

A synonym is created as follows:

CREATE SYNONYM [AnotherDatabase_dbo].[MyTable] FOR [AnotherDatabase].[dbo].[MyTable]

I create a data context as follows:

type dbSchema = SqlDataConnection<"Data Source=MyServer\MyInstance;Initial Catalog=MyDatabase;Integrated Security=SSPI;">
let db = dbSchema.GetDataContext ()

How can I access a synonym from F #?

+4
source share
1 answer

, , F #. FSharp.Data, NuGet : http://fsharp.imtqy.com/FSharp.Data/. NB: SQL 2012 .

open FSharp.Data

[<Literal>]
let connectionString = @"Data Source=MyServer\MyInstance;Initial Catalog=MyDatabase;Integrated Security=SSPI;"

[<Literal>]
let query = "select Id, Name from MyTable" 

type OptionQuery = SqlCommandProvider<query, connectionString>
let cmd = new OptionQuery()

cmd.AsyncExecute() 
|> Async.RunSynchronously
|> Seq.iter (fun row -> printfn "Found row: %d %s" row.Id row.Name)

System.Console.Write("Done")
System.Console.ReadKey()
+1

Source: https://habr.com/ru/post/1548075/


All Articles