Reputation: 3447
Working with a model first approach on Entity Framework 4, I'd like to switch the database from real SQL (Data.SQLClient) to SQL CE (Data.ServerCe) back and forth.
I know how to do it manually:
Change the provider from System.Data.SqlServerCe.3.5 to System.Data.SqlClient
What I can't figure out is how I could make that change at build/compile time, so I could easily switch between SQLClient and SQLServerCE based on a configuration.
Any other way how to achieve the same result would be appreciated too! (have one model where the data source can be switched between SQL and SQL CE)
Upvotes: 2
Views: 1207
Reputation: 27995
I don't know if its the best way for you in this situation, however I would just like to make sure that you know of this way to solve your problem.
You can (right) click inside the designer view of your edmx (not on the file in the solution explorer) and click "Properties", in the PropertyGrid look for "Metadata Artifact Processing" and change the value from "Embed in Output Assembly" to "Copy to Output Directory".
However, once you changed this, instead of having the edmx baked into the assembly, you will notice three XML based files (MyModel.ssdl, MyModel.csdl, MyModel.msl) in your output directory.
You are now free to script any changes to those files as a part of your build process.
Also make sure to change your connection string to something like this:
<add name="MyEntities" connectionString="metadata=.\MyModel.csdl|.\MyModel.ssdl|.\MyModel.msl; (..) />
As I said, I'm not sure if it will be the best approach for your specific problem. However, I use it to generate different builds for different database schemas. It works.
Upvotes: 2