How to speed up build time for F# project with SQL TypeProvider

It is good to read documentation. There is so many useful information that might save a lot of time…
I’m working on some project, where I use F# TypeProviders to connect with some legacy database. And each time I built my project, I was reloading database scheme. So each build took too long. At first, I’ve moved my F# code to new solution, so I didn’t have to wait for it each time I was testing my app. But sometimes I still have to fix and rebuild part of the code with data access. I it still took a lot of time. And today comes realization: „Maybe there is some way to cache database scheme?”.
Of course it is, it is F#!
When declaring SqlDataConnection type provider, there two additional parameters that could be use:

  • LocalSchemaFile
  • ForceUpdate

First one is just path to file, second one could be used to force VS to regenerate cached file if there were some change in application. Nice thing is that such file could be shared amongst other F# projects, you just need to put correct path. As I have two projects in solution: first with data access for my application and second with some tests, my context definition for both projects looks like that:

type internal EntityConnection = SqlDataConnection<ConnectionStringName="appTypeProvider",ConfigFile="App.exe.config", LocalSchemaFile="../appSchema.dbml", ForceUpdate=false>

Dump data from SQL to CSV (or other format) with F#

Recently I started playing with F#. And when I looked up for a way of accessing data, I found something called TypeProvider. And I have to say it is amazing tool. Then I realized that I was looking for some simple way to dump part of my database to CSV file, so I can use this data in automated testing (I might write something about that in near future). And I could use F# to just do it!
The result of my work was code that could dump selected tables (or part of selected tables) into separate CSV files (or in any other format, if you change function that dumps data). It will automatically get all columns in your database, so you have to only list tables that you want to dump (or write some simple F# query to get only data you want – useful if you have tables with millions of records, and don’t want to dump all of them).

Here is description of how it is done: (or you can just look on full source code).
Czytaj dalej Dump data from SQL to CSV (or other format) with F#