F#类型提供程序和连续集成 [英] F# Type Providers and Continuous Integration

查看:242
本文介绍了F#类型提供程序和连续集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

F#类型提供程序的类型定义通常需要一个常量表达式,例如。对于SQL类型提供程序:

  type dbSchema = SqlDataConnection<Data Source = MySqlServer; Initial Catalog = MyDatabase;>然而,当提交代码到SCM,并进一步有一个构建服务器做它的东西,你可能不想使用相同的连接字符串,而是从构建过程生成的SQL服务器数据库的连接字符串。 



有这个问题的解决方案吗?



这将是非常好的能够使这项工作,因为它将提供对数据库访问代码的编译时检查。



更新
@tomaspetricek提出的解决方案非常好,但是我必须为连接字符串添加一个提供者名称:

 < add name =DbConnectionStringproviderName = System.Data.SqlClientconnectionString =Data Source = MySqlServer; Initial Catalog = MyDatabase;/> 


解决方案

配置文件(请参见 MSDN文档):

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

一般来说,类型提供者可能需要一些常量表达式,但我认为大多数广泛使用的提供一种避免这种情况的方法。例如, SqlDataConnection 可以从配置文件中读取设置,其他标准的F#类型提供程序允许指定 LocalSchemaFile 在本地指定必要的结构(例如 *。dbml SQL文件)。



F#数据类型提供程序可以将URL作为远程文件,但也可以使用本地文件。所以我认为应该总是有一种方法来指定信息而不指定常量连接字符串(等) - 但随时要问具体的提供程序。


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;"/>

解决方案

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.

这篇关于F#类型提供程序和连续集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆