Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Entity Framework provider in configuration

I was hoping to be able to switch data providers to/from SQL Server and SQL Server Compact Edition via just a configuration change. But it doesnt work and looking at the EDMX file I think I can see why:

<edmx:StorageModels>
<Schema ... Provider="System.Data.SqlClient" ...

Is there any way to specify the provider in app.config or at runtime?

like image 556
user380689 Avatar asked Sep 10 '25 18:09

user380689


1 Answers

The Storage-Model is tied to a specific provider, which will cause the Entity Framework to reject any DbConnection implementations that are not compatible with the specified provider.

If you look at an Entity Framework connection-string, you can see that the StorageSchema, ModelSchema and Mapping are specified in three different files (which are generated from your .edmx and than embedded in the assembly). You could take your .edmx apart and embed the .ssdl, .csdl and .msl yourself and than create another .ssdl for SQL Server CE. This is basically just copy & paste and replacing the provider and some column-types.

I wrote about here: Comparison Entity Framework

like image 152
J. Tihon Avatar answered Sep 13 '25 06:09

J. Tihon