F# Type Providers very very slow build

2020-06-04 12:54发布

I'm playing around with Type Providers, specifically the sql entity framework type provider. I'm writing tests against a database that has a LOT of objects, and it's remote so the connection is a little slow. every time i build the project it takes a lot of time, good several minutes for the build to complete.

what am I missing why does the compiler doesn't cache the type information?

P.S. It's even worse with F# interactive....

3条回答
beautiful°
2楼-- · 2020-06-04 13:32

Seems like bottleneck is in remote connection. I also assume you have to edit and recmpile db access code frequently.

Some type providers can point to local SQL scripts instead of live connection, if it's not the case then make a local db which will replicate the schema (and static data in 'enum' tables if you have any). Connection for type providers/compiler and for runtime doesn't have to be the same.

There are tools to sync schemas once in a while e.g.Red Gate SQL Compare (this is one is great but not free), or simply regenerate full db schema SQL and recreate local database and run it once in a while (this also can be automated but it's a different story).

查看更多
叼着烟拽天下
3楼-- · 2020-06-04 13:35

Besides what can be defined as a 'slow build', (if you are in the red green tdd development circle, builds quickly become slow!), I moved my client type provider code to a separate project. I already had ForceUpdate set to false, but still builds were slow (apparently still some background checking of the generated dbml files was going on, in my case wsdlschema files actually).

After moving all the type provider code to a separate projects, builds were significantly faster!

Note: loading the interactive was even more quick, only you have to add the reference to the dll for the types

查看更多
\"骚年 ilove
4楼-- · 2020-06-04 13:45

Try using the LocalSchemaFile attribute for the data provider. This points to a .csdl file that is used to generate the types. You can have the type provider update this file by setting the ForceUpdate attribute to true. To run from a cached schema simply set ForceUpdate to false. Here is how I do this with the SqlDataConnection provider, which is very similar to the SqlEntityConnection provider.

type schema = SqlDataConnection< LocalSchemaFile = "Schema.dbml", ForceUpdate = false, ConnectionString = @"Data Source=<insert your connection string here>" >
查看更多
登录 后发表回答