Unable to determine the provider name for the connection of type "System.Data.SqlServerCe.SqlCeConnection"

I use the Ado.Net Entity Framework with code only (tutorial at: ADO.NET Team Blog ) and I want to be as large a database as possible.

In my first approach, I just want to find the Sql Express and Sql Compact databases. Everything works fine with Sql Express, but with Sql Compact, I get the exception mentioned in my question.

Does anyone know if it is possible to connect to Sql Compact using the Code Only approach? (everything works fine with the created .edmx file for the Sql Compact database, but I want to use only the code!)

Here is the code:

My class that creates the DataContext:

public class DataContextBuilder : IDataContextBuilder { private readonly DbProviderFactory _factory; public DataContextBuilder(DbProviderFactory factory) { _factory = factory; } #region Implementation of IDataContextBuilder public IDataContext CreateDataContext(string connectionString) { var builder = new ContextBuilder<DataContext>(); RegisterConfiguration(builder); var connection = _factory.CreateConnection(); connection.ConnectionString = connectionString; var ctx = builder.Create(connection); return ctx; } #endregion private void RegisterConfiguration(ContextBuilder<DataContext> builder) { builder.Configurations.Add(new PersonConfiguration()); } } 

Line

var ctx = builder.Create (connection);

throws an exception.

IDataContext is just a simple interface for ObjectContext:

 public interface IDataContext { int SaveChanges(); IObjectSet<Person> PersonSet { get; } } 

My connection string is configured in app.config:

 <connectionStrings> <add name="CompactConnection" connectionString="|DataDirectory|\Test.sdf" providerName="System.Data.SqlServerCe.3.5" /> </connectionStrings> 

And the build action starts with

 var cn = ConfigurationManager.ConnectionStrings["CompactConnection"]; var factory = DbProviderFactories.GetFactory(cn.ProviderName); var builder = new DataContextBuilder(factory); var context = builder.CreateDataContext(cn.ConnectionString); 
+4
source share
1 answer

I have to answer my question.

Now it works with Entity Framework CTP 4

and SQL Server Compact 4.0

+3
source

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


All Articles