fsprojects / fsprojects/FSharp.Data.SqlClient

SqlProgrammabilityProvider requires open SqlConnection

Open
#245 14 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
F#
Stars
206
Forks
66
PR merge metrics
No merged PRs in 30d

Description

Description

The CreateCommand on SqlProgrammabilityProvider is a great idea as it means that we just need a single type for the DB, whether for ad-hoc queries or inserts using datatables etc. However, the arguments required by the CreateCommand method could be improved: -

Repro steps

This is the current way that you use the provider: -

type AdventureWorks = SqlProgrammabilityProvider<Conn>
let conn = new System.Data.SqlClient.SqlConnection(Conn)
conn.Open()
let customers = AdventureWorks.CreateCommand<"SELECT * FROM SalesLT.Customer">(conn).Execute() |> Seq.toArray
Expected behavior

This is what I would prefer to see: -

type AdventureWorks = SqlProgrammabilityProvider<Conn>
let customers = AdventureWorks.CreateCommand<"SELECT * FROM SalesLT.Customer">(Conn).Execute() |> Seq.toArray // use string rather than open SQL connection object

Or even better: -

type AdventureWorks = SqlProgrammabilityProvider<Conn>
let customers = AdventureWorks.CreateCommand<"SELECT * FROM SalesLT.Customer">().Execute() |> Seq.toArray // connection string is optional
Known workarounds

I suppose you could write an extension method or similar that takes in the command with a constraint of something like (pseudo code) (conn:SqlConnection) -> execute() -> Seq<'T> but this is not ideal.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SqlProgrammabilityProvider.CreateCommand usage shown in the repro and compare it with the two expected calling forms. Determine whether the provider should accept a connection string or no argument, then verify that the sample query executes and returns the expected sequence of customers.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp, sql
Domain
api, database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.