本文介绍了如何使用F#中的类型提供程序连接到SQL Server Compact Edition 4.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从F#连接到SQL Server Compact Edition数据库,并尝试使用类型提供程序.这是在Visual Studio 11 Beta中提供的,因此我意识到可能有一个问题,但是我认为我还很可能还不知道该怎么做.

I'm attempting to connect to a SQL Server Compact Edition database from F#, and attempting to use a type provider. This is in the Visual Studio 11 Beta, so I realize there might be an issue because of that, but I think it's more likely that I just don't have the know-how yet.

但是,我注意到Microsoft.FSharp.Data.TypeProviders中没有特定于CE的类型提供程序,而且我不确定常规的SqlDataConnection是否可以解决问题,所以这可能就是问题所在.

However, I have noticed that there's no CE-specific type provider in Microsoft.FSharp.Data.TypeProviders and I'm unsure that a regular SqlDataConnection will do the trick, so that may be the issue right there.

但是,当我尝试创建连接时,IDE似乎至少意识到我正在尝试访问CE数据库.

However, when I try to create the connection, the IDE seems to recognize that I'm trying to hit a CE database, at least.

所以,我有以下代码:

type SqlConnection =
  Microsoft.FSharp.Data.TypeProviders
    .SqlDataConnection<ConnectionString = @"Data Source=C:\\Path\\Database.sdf">
let db = SqlConnection.GetDataContext()

所以这很标准,使用类型提供程序项菜单将新的LINQ添加到SQL或多或少都是直接的.

So it's pretty standard, more or less straight out of the add new LINQ to SQL with type provider item menu.

我通过连接字符串得到的工具提示是未安装提供程序'System.Data.SqlServerCe.3.5'".查找该内容似乎表明未安装Sql Server CE是一个问题,但是我拥有这些库,能够使用常规SqlCEConnection连接到数据库并运行SqlCeCommands等.而且由于它是4.0而不是3.5,所以我不确定它是否在寻找错误的提供程序.我是在VS 11 beta中创建数据库的,所以我想所有版本都应该匹配.

The tooltip I get over the connection string is "Provider 'System.Data.SqlServerCe.3.5' not installed." Looking that up seems to indicate that it's a problem with not having Sql Server CE installed, but I've got the libraries, am able to connect to the database using a regular SqlCEConnection and running SqlCeCommands and such. And since it's 4.0 and not 3.5, I'm not sure if it's looking for the wrong provider. I created the database right in VS 11 beta, so I was figuring that all versions should match up and such.

因此,简而言之,我想知道我是在做错什么,还是VS11 beta类型提供程序库不支持CE 4.0,或者是否需要做一些其他事情才能使其实现.

So in short, I'm wondering if I'm doing something wrong, or if the VS11 beta type provider libraries don't support CE 4.0 yet, or if there is something else I need to do to make it happen.

谢谢!

推荐答案

此在我的机器上工作"(基于VS 11 beta,实体框架,基于此处的演练http://msdn.microsoft.com/en-us/library/hh361038(v=vs.110).aspx:

This "Works on my Machine" (using VS 11 beta, Entity Framework, based on the walkthrough here, http://msdn.microsoft.com/en-us/library/hh361038(v=vs.110).aspx :

open System.Data.Linq
open System.Data.EntityClient
open Microsoft.FSharp.Data.TypeProviders

let connectionString = "metadata=res://*/;provider=System.Data.SqlServerCe.4.0;provider connection string='data source=C:\\Data\\SQLCE\\Test\\nw40.sdf';"

type internal edmx = EdmxFile<"NWModel.edmx", ResolutionFolder = @"C:\Users\erik.COMMENTOR\Documents\Visual Studio 11\Projects\TestSqlCeFSharp">

let internal context = new edmx.nw40Model.nw40Entities(connectionString)

query { for supplier in context.Suppliers do
        select supplier }
|> Seq.iter (fun supplier -> printfn "%s" supplier.Company_Name)

添加了对以下内容的引用:FSharp.Data.TypeProviders,System.Data.Entity,System.Data.Linq

Added references to:FSharp.Data.TypeProviders,System.Data.Entity,System.Data.Linq

这篇关于如何使用F#中的类型提供程序连接到SQL Server Compact Edition 4.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 00:41