F# Type Providers and Continuous Integration

穿精又带淫゛_ 提交于 2019-12-10 12:43:23

问题


The type definition of an F# type provider often requires a constant expression, e.g. for the SQL type provider:

type dbSchema = SqlDataConnection<"Data Source=MySqlServer;Initial Catalog=MyDatabase;">

However, when committing the code to SCM, and further having a build server doing its thing, you probably don’t want to use the same connection string, but rather the connection string of a SQL server database that is generated from the build process.

Is there a solution for this problem?

It would be really nice to be able to make this work, as it would provide a compile-time check of the database access code.

Update The solution proposed by @tomaspetricek worked very well, but I had to add a provider name to the connection string:

<add name="DbConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=MySqlServer;Initial Catalog=MyDatabase;"/>

回答1:


You can certainly specify the connection string using a key in a configuration file (see MSDN documentation):

SqlDataConnection<ConnectionStringName="...", ConfigFile="app.config">

In general, a type provider may require some constant expression, but I think most of the widely used ones provide a way for avoiding this. For example, SqlDataConnection can read the setting from configuration file, other standard F# type providers allow specifying LocalSchemaFile that allows you to specify the necessary structure locally (e.g. *.dbml file for SQL).

The F# Data type providers can take URL to a remote file, but they can also take local file. So I think that there should always be a way to specify the information without specifying a constant connection string (etc.) - but feel free to ask about specific providers.



来源:https://stackoverflow.com/questions/18969181/f-type-providers-and-continuous-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!