Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One POCO model with different data providers

I have a client application (WPF, C#, .net4) which uses POCO entity model connected through SQLITE provider. So I want to have same entities from this project in an asp.net project (with MSSQL provider), to use there the same entities that I use in my client application. I want to create some kind of replication functionality between my client app (SQLITE) and web server (MSSQL) using same poco model using web services.

So I have a reference to my entities model in both projects with different connection strings for edmx files. And in this case (because edmx was compiled for sqlite provider) when I'm trying to use mssql data provider I get an exception:

unable to cast System.Data.SqlConnection to System.Data.SQliteConnection

So my question is if it is possible to use different data providers in one entities model? What is the best way to use same model in different projects?

like image 209
DolceVita Avatar asked Nov 15 '22 05:11

DolceVita


1 Answers

If I understand your question correctly, then if you are looking for your EF model to support multiple database implementations then this is not possible out of the box. The SSDL file auto-generated by EF will contain provider specific metadata and therefore will restrict its independence from the different database implementations you are using.

There are some articles out there providing ways around this, but this requires a separate copy of your model for each provider and hacking the generated XML with the provider details.

like image 167
Pero P. Avatar answered Dec 22 '22 12:12

Pero P.