How to connect to SQL Server Compact Edition 4.0 with type provider in F #?

I am trying to connect to a SQL Server Compact Edition database from F # and am trying to use a type provider. This is in beta version of Visual Studio 11, so I understand that this may cause a problem, but I think it’s more likely that I don’t have the know-how yet.

However, I noticed that Microsoft.FSharp.Data.TypeProviders does not have a CE type provider, and I'm not sure that a regular SqlDataConnection will do the trick, so that might be the problem right there.

However, when I try to create a connection, the IDE seems to recognize that I am trying to get into the CE database, at least.

So, I have the following code:

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

So, this is pretty standard, more or less directly from adding LINQ to SQL from the item menu of the merchandise provider.

The tooltip that I get above the connection string is “Provider” System.Data.SqlServerCe.3.5 “not installed”. It seems like this indicates that the problem is due to the lack of Sql Server CE, but I have libraries, I can connect to the database using regular SqlCEConnection and run SqlCeCommands, etc. And since it is 4.0 and not 3.5, I'm not sure if it is looking for the wrong provider. I created the database directly in VS 11 beta, so I decided that all versions should be the same.

In short, I am wondering if I am doing something wrong, or if the VS11 beta testing provider libraries do not yet support CE 4.0, or if there is something else that I need to do to make this happen.

Thanks!

+6
source share
2 answers

This "works on my machine" (using VS 11 beta, an Entity Framework based on going 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) 

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

+5
source
 Supported info of 'System.Data.SqlServerCe.4.0' in Microsoft.FSharp.Data.TypeProviders 1.SqlDataConnection is not 2.DbmlFile is partial type dbml = DbmlFile<_> use cn = new SqlCeConnection(...) use db = new dbml.DbContext(cn) 3.EdmxFile is full 4.SqlEntityConnection is full 
+2
source

Source: https://habr.com/ru/post/913208/


All Articles