fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
570 stars 144 forks source link

[Question] offline lookup for SqlDataProvider [info] #629

Closed giuliohome closed 4 years ago

giuliohome commented 5 years ago

Maybe this feature is already implemented, but let's say I have

type Sql = SqlDataProvider<
            Common.DatabaseProviderTypes.MSSQLSERVER, 
            @"Data Source=...;Initial Catalog=...;User ID=...;Password=...">

Now I compile my solution and I can double check all my type safe fields at compile time. So far, so good. Assume that I want to work offline for a period and I know that the DB is not changed and I want to code a different part of the solution, that is not DB related. At the moment I'm not able to compile offline, but again maybe there is an option for the SqlDataProvider to cache/store the type info for this use case, is it possible?

giuliohome commented 5 years ago

I think I will solve this problem by moving the sql part into a separate lib that won't be compiled when I work on the rest of the project. I hope it should suffice.

Anyway, I'll keep this issue open for a while, just to receive any possible feedback from the others.

Thorium commented 5 years ago

Yes this is done, via the ContextSchemaPath parameter: https://fsprojects.github.io/SQLProvider/core/parameters.html#ContextSchemaPath

giuliohome commented 5 years ago

Awesome!!! Thank you very much for the link to the explanation. I tried to find it but I missed it. It looks perfect, at first glance, and I will study this parameter usage when back from holiday. Thank you again, sqlprovider is a great project.

giuliohome commented 4 years ago

This is what I've tried

 [<Literal>]
 let contextSchemaPath =
     __SOURCE_DIRECTORY__ + @"\.sqlserver.schema" // fixed misspelt .\
 type Sql = SqlDataProvider<
             DatabaseVendor = Common.DatabaseProviderTypes.MSSQLSERVER, 
             ConnectionString = @"Valid Conn String"
             ContextSchemaPath = contextSchemaPath>

I'm calling

 member x.cache() =
     let result = context.SaveContextSchema()
     printfn "check schema under %s with result %A" 
         myPath  result

from F# interactive (btw fyi this is how I skip the configurationmanager in fsi) but I see a null result from SaveContextSchema and nothing under the schema path (I've also replace the string with absolute path without the __SOURCE_DIRECTORY__ symbol)

Type the method name with parentheses, if you then type a dot (.), you should see a tooltip with information when the schema was last saved.

Actually I see that there is an access denied error (I'm wondering why though) for any possible path I've tried...

``Save failed: Accesso al percorso '...' negato.``

Compiled the lib proj under a working connection and then reopened offline... without luck ... what I'm still missing? Thanks again

giuliohome commented 4 years ago

Understood! after fixing the misspelt __SOURCE_DIRECTORY__ + @".\blabla in the documentation (!) with a more likely __SOURCE_DIRECTORY__ + @"\.blabla... I've also realized that ContextSchemaPath must be the path to a file to be created, not to a folder. All's working as expected. Thank you again!)