Skip to content

[WIP] Target Microsoft.Data.SqlClient #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ nuget/*.nupkg
packages
docs/output
temp
ignore/
.vs/

#################
Expand Down
39 changes: 0 additions & 39 deletions Samples.sln

This file was deleted.

76 changes: 39 additions & 37 deletions build.fsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Fake.DotNet
// --------------------------------------------------------------------------------------
// FAKE build script
// FAKE build script
// --------------------------------------------------------------------------------------

#r @"packages/build/FAKE/tools/FakeLib.dll"
Expand All @@ -19,10 +19,10 @@ open Fake.DotNet

Environment.CurrentDirectory <- __SOURCE_DIRECTORY__

let files includes =
let files includes =
{ BaseDirectory = __SOURCE_DIRECTORY__
Includes = includes
Excludes = [] }
Excludes = [] }

// Information about the project to be used at NuGet and in AssemblyInfo files
let project = "FSharp.Data.SqlClient"
Expand All @@ -31,13 +31,13 @@ let authors = ["Dmitry Morozov, Dmitry Sevastianov"]
let summary = "SqlClient F# type providers"
let description = "SqlCommandProvider provides statically typed access to input parameters and result set of T-SQL command in idiomatic F# way.\nSqlProgrammabilityProvider exposes Stored Procedures, User-Defined Types and User-Defined Functions in F# code."
let tags = "F# fsharp data typeprovider sql"

let gitHome = "https://github.com/fsprojects"
let gitName = "FSharp.Data.SqlClient"

// Read release notes & version info from RELEASE_NOTES.md
let release =
File.ReadLines "RELEASE_NOTES.md"
let release =
File.ReadLines "RELEASE_NOTES.md"
|> Fake.Core.ReleaseNotes.parse

let version = release.AssemblyVersion
Expand Down Expand Up @@ -76,7 +76,7 @@ let testProjectsSlnPath = "TestProjects.sln"
let testSlnPath = "Tests.sln"
let testProjectPath = "tests/SqlClient.Tests/SqlClient.Tests.fsproj"
let runMsBuild project =
Fake.DotNet.MSBuild.build
Fake.DotNet.MSBuild.build
(fun args ->
let toolPath =
[
Expand All @@ -90,13 +90,13 @@ let runMsBuild project =
@"C:\Program Files (x86)\MSBuild\15.0\Bin"
@"\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
args.ToolPath
]
]
|> List.map (fun p -> Path.Combine(p, "MSBuild.exe"))
|> List.find File.Exists
let properties =
let properties =
[ yield "Configuration", "Release"
for n,v in args.Properties do
if n <> "Configuration" then
for n,v in args.Properties do
if n <> "Configuration" then
yield n,v
]
{ args
Expand All @@ -118,14 +118,14 @@ Target.create "CleanDocs" (fun _ ->

Target.create "Build" (fun _ ->
DotNet.build
(fun args ->
{
args with
(fun args ->
{
args with
Configuration = DotNet.Release
//Common = { args.Common with Verbosity = Some DotNet.Verbosity.Detailed }
} |> dnDefault)
slnPath

)

#r "System.Data"
Expand All @@ -134,16 +134,18 @@ Target.create "Build" (fun _ ->
#r "System.IO.Compression"
#r "System.IO.Compression.FileSystem"

open System.Data.SqlClient
#r "nuget: Microsoft.Data.SqlClient"

open Microsoft.Data.SqlClient
open System.Configuration
open System.IO.Compression

Target.create "DeployTestDB" (fun _ ->
let testsSourceRoot = Path.GetFullPath(@"tests\SqlClient.Tests")
let map = ExeConfigurationFileMap()
map.ExeConfigFilename <- testsSourceRoot @@ "app.config"
let connStr =
let x =
let connStr =
let x =
ConfigurationManager
.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None)
.ConnectionStrings
Expand All @@ -152,34 +154,34 @@ Target.create "DeployTestDB" (fun _ ->
SqlConnectionStringBuilder(x)

let database = connStr.InitialCatalog
use conn =
use conn =
connStr.InitialCatalog <- ""
new SqlConnection(string connStr)

conn.Open()

do //attach
let dbIsMissing =
let dbIsMissing =
let query = sprintf "SELECT COUNT(*) FROM sys.databases WHERE name = '%s'" database
use cmd = new SqlCommand(query, conn)
cmd.ExecuteScalar() = box 0

if dbIsMissing
then
then
let dataFileName = "AdventureWorks2012_Data"
//unzip
let sourceMdf = testsSourceRoot @@ (dataFileName + ".mdf")

if File.Exists(sourceMdf) then File.Delete(sourceMdf)

ZipFile.ExtractToDirectory(testsSourceRoot @@ (dataFileName + ".zip"), testsSourceRoot)


let dataPath =
let dataPath =
use cmd = new SqlCommand("SELECT SERVERPROPERTY('InstanceDefaultDataPath')", conn)
cmd.ExecuteScalar() |> string
do
let destFileName = dataPath @@ Path.GetFileName(sourceMdf)
let destFileName = dataPath @@ Path.GetFileName(sourceMdf)
File.Copy(sourceMdf, destFileName, overwrite = true)
File.Delete( sourceMdf)
use cmd = new SqlCommand(Connection = conn)
Expand All @@ -199,15 +201,15 @@ Target.create "BuildTestProjects" (fun _ ->
)

// --------------------------------------------------------------------------------------
// Run the unit tests
Target.create "RunTests" (fun _ ->
// Run the unit tests
Target.create "RunTests" (fun _ ->
// if we don't compile the targets sequentially, we get an error with the generated types:
// System.IO.IOException: The process cannot access the file 'C:\Users\foo\AppData\Local\Temp\tmpF38.dll' because it is being used by another process.
DotNet.restore dnDefault testSlnPath
runMsBuild testSlnPath
try
try
DotNet.test (fun args -> { args with Framework = Some "net461"; Common = args.Common |> dnDefault }) testSlnPath
DotNet.test (fun args -> { args with Framework = Some "netcoreapp2.0"; Common = args.Common |> dnDefault }) testProjectPath
DotNet.test (fun args -> { args with Framework = Some "netcoreapp3.1"; Common = args.Common |> dnDefault }) testProjectPath
with
| ex ->
Trace.log (sprintf "Test exception: %A" ex)
Expand All @@ -222,9 +224,9 @@ Target.create "NuGet" (fun _ ->
// Format the description to fit on a single line (remove \r\n and double-spaces)
let description = description.Replace("\r", "").Replace("\n", "").Replace(" ", " ")
let nugetPath = "packages/build/NuGet.CommandLine/tools/NuGet.exe"
Fake.DotNet.NuGet.NuGet.NuGet (fun p ->
{ p with

Fake.DotNet.NuGet.NuGet.NuGet (fun p ->
{ p with
Authors = authors
Project = project
Summary = summary
Expand All @@ -247,7 +249,7 @@ Target.create "GenerateDocs" (fun _ ->
Fake.FSIHelper.executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore
)

Target.create "ServeDocs" (fun _ ->
Target.create "ServeDocs" (fun _ ->
Fakeiisexpress.HostStaticWebsite id (__SOURCE_DIRECTORY__ @@ @"docs\output\") |> ignore
Fakeiisexpress.OpenUrlInBrowser "http://localhost:8080"
)
Expand All @@ -274,16 +276,16 @@ open Fake.Core.TargetOperators // for ==>
"Clean"
==> "AssemblyInfo"
==> "Build"
==> "DeployTestDB"
==> "BuildTestProjects"
==> "DeployTestDB"
==> "BuildTestProjects"
==> "RunTests"
==> "All"

"All"
"All"
==> "NuGet"
==> "Release"

"All"
"All"
==> "CleanDocs"
==> "GenerateDocs"
==> "ReleaseDocs"
Expand Down
4 changes: 2 additions & 2 deletions docs/content/configuration and Input.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ module DB =
[<Literal>]
let connStr = @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True"

open System.Data.SqlClient
open Microsoft.Data.SqlClient

type MyCmd1 = SqlCommandProvider<"SELECT 42", connStr>
type MyCmd2 = SqlCommandProvider<"SELECT 42", connStr>
Expand Down Expand Up @@ -291,7 +291,7 @@ type GetBitCoin =

do
let cmd = new DeleteBitCoin(connStr) in cmd.Execute(bitCoinCode) |> ignore
let conn = new System.Data.SqlClient.SqlConnection(connStr)
let conn = new Microsoft.Data.SqlClient.SqlConnection(connStr)
conn.Open()
let tran = conn.BeginTransaction()

Expand Down
4 changes: 2 additions & 2 deletions docs/content/data modification.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ do

currencyRates.Rows.Add newRow
//Insert many more rows here
currencyRates.BulkCopy(copyOptions = System.Data.SqlClient.SqlBulkCopyOptions.TableLock)
currencyRates.BulkCopy(copyOptions = Microsoft.Data.SqlClient.SqlBulkCopyOptions.TableLock)

(**

Expand All @@ -291,7 +291,7 @@ customize update behavior by creating your own instance of [SqlDataAdapter](http
Pseudocode for custom data adapter:
*)

open System.Data.SqlClient
open Microsoft.Data.SqlClient

do
let currencyRates = new AdventureWorks.Sales.Tables.CurrencyRate()
Expand Down
4 changes: 2 additions & 2 deletions docs/content/faq.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ With a datareader obtained from a custom command you can still reuse the typed r
let getDatesQuery = "SELECT GETDATE() AS Now, GETUTCDATE() AS UtcNow"
type GetDates = SqlCommandProvider<getDatesQuery, connectionString>

open System.Data.SqlClient
open Microsoft.Data.SqlClient
type SqlDataReader with
member this.ToRecords<'T>() =
seq {
Expand All @@ -120,7 +120,7 @@ type SqlDataReader with
let xs =
use conn = new SqlConnection(connectionString)
conn.Open()
let cmd = new System.Data.SqlClient.SqlCommand(getDatesQuery, conn)
let cmd = new Microsoft.Data.SqlClient.SqlCommand(getDatesQuery, conn)
cmd.ExecuteReader().ToRecords<GetDates.Record>()
|> Seq.toArray

Expand Down
2 changes: 1 addition & 1 deletion docs/content/output.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ In later case, resulting `SqlDataReader` can be wrapped into something like that
*)

module SqlDataReader =
open System.Data.SqlClient
open Microsoft.Data.SqlClient
let toMaps (reader: SqlDataReader) =
seq {
use __ = reader
Expand Down
4 changes: 2 additions & 2 deletions docs/content/sqlenumprovider.quickstart.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ A typical implementation for overnight orders shipped since Jan 1, 2008 is follo
let connStr = @"Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True"

open System
open System.Data.SqlClient
open Microsoft.Data.SqlClient

let conn = new SqlConnection (connStr)
conn.Open()
Expand Down Expand Up @@ -220,7 +220,7 @@ Miscellaneous

### Any ADO.NET supported database
SqlEnumProvider has a static parameter "Provider" which allows to pass ADO.NET provider [invariant name](http://msdn.microsoft.com/en-us/library/h508h681.aspx).
This makes it usable with any ADO.NET supported database. "System.Data.SqlClient" is default value for ADO.NET provider.
This makes it usable with any ADO.NET supported database. "Microsoft.Data.SqlClient" is default value for ADO.NET provider.

Invariant names of available ADO.NET providers can be retrieved as follows:
*)
Expand Down
2 changes: 1 addition & 1 deletion docs/content/transactions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This conforms to familiar [ADO.NET conventions](https://msdn.microsoft.com/en-us
*)

open System
open System.Data.SqlClient
open Microsoft.Data.SqlClient

type CurrencyCode =
SqlEnumProvider<"SELECT Name, CurrencyCode FROM Sales.Currency", connectionString>
Expand Down
2 changes: 1 addition & 1 deletion docs/content/whatsnew.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Any of these parameters can be ommited.
#r "System.Transactions"

do
use conn = new System.Data.SqlClient.SqlConnection( connectionString)
use conn = new Microsoft.Data.SqlClient.SqlConnection( connectionString)
conn.Open()
use tran = conn.BeginTransaction()
use cmd =
Expand Down
Loading