Last active
May 27, 2020 15:26
-
-
Save JordanMarr/7e7d3d1337bc494e9c89977f32ffc2be to your computer and use it in GitHub Desktop.
SQLProvider - Clearing the schema cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyApp.Database.SqlProvider = | |
open FSharp.Data.Sql | |
open System.Data | |
#if DEBUG | |
// Print generated SQL to console | |
FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %O") | |
#endif | |
[<Literal>] | |
let contextSchemaPath = __SOURCE_DIRECTORY__ + @"\.sqlserver.schema" | |
(* SQLProvider is a Type Provider that generates strongly typed objects for database tables. | |
The schema is cached below in the "ContextSchemaPath". | |
If the database schema changes, you must do the following to update the cache: | |
1) Comment out the "ContextSchemaPath" line below and save (this will cause the Type Provider to hit the database). | |
2) Implement the new functionality (create new query expressions) and save. | |
3) Delete the file ".sqlserver.schema" from this project folder. | |
4) Uncomment the "ContextSchemaPath" line below; | |
Uncomment __TypeProviderSupport "ctx.SaveContextSchema()" (this will cause it to save schema on next build). | |
5) REBUILD project and verify that the ".sqlserver.schema" file has been recreated. | |
6) Comment out __TypeProviderSupport "ctx.SaveContextSchema()" (to prevent it from continually rebuilding the schema file). | |
7) If there are build errors, close and reopen the solution to clear the errors. *) | |
type DB = SqlDataProvider< | |
Common.DatabaseProviderTypes.MSSQLSERVER, | |
"Server=myserver;Database=mydb;User Id=someuser;Password=somepw;", | |
IndividualsAmount = 5, | |
ContextSchemaPath = contextSchemaPath, | |
UseOptionTypes = true> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This module automatically saves the type provider schema file during design-time compilation. | |
/// NOTE: This file must exist at the end of the project (or after all the usages of the type provider), | |
/// because it will only cache tables / columns that have been used in expression queries before this point. | |
module MyApp.__TypeProviderSupport = | |
let schema = | |
//let ctx = MyApp.Database.SqlProvider.DB.GetDataContext() | |
//ctx.SaveContextSchema() | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment