I have a solution with 2 projects:
- F# project (for data access + other functions)
- C# web project (will consume functions from F#)
I will need to call SQL Server stored procedures, and am using FSharp.Data.TypeProviders to do the job.
type dbSchema = SqlDataConnection< "...", StoredProcedures=true >
let getDbContext connString =
match connString with
| "" -> dbSchema.GetDataContext()
| _ -> dbSchema.GetDataContext(connString)
Insert:
let insertItem dbContext item =
dbContext.CreateStoredProc(item.Stuff)
Or
let insertItem connString item =
use dbContext = getDbContext connString
dbContext.CreateStoredProc(item.Stuff)
- How would I consume this from C# so that I'm not recreating the
dbContextevery time I do an insert?
I don't want to expose the whole dbContext, just certain stored procedures through the F# DAL.
Note: I need to pass in the connection string from web.config
Similar question here doesn't fully provide my answer: F# Type Provider for SQL in a class
- I am able to set
getDbContextto internal or private, but notdbSchema. Any way to not expose it?