This is my take on a similar scenario (very similar to @Greatran answer, but I could not find any Metadata artifact processing property item on my .EDMX file):
- Build at least once your project containing the EDMX file
- Grab a copy of generated .SSDL file, contained in a subpath of
Your\Project\Folder\obj\Debug\edmxResourcesToEmbed\Your\EDMX\Namespace\
- Copy and include that under your project, e.g. in the same directory as EDMX file:
...\Your\EDMX\Namespace\MyModel.ssdl
- Rename it adding a suffix to match your deploy environment, so e.g. for
Debug
environment it would be MyModel.Debug.ssdl
- From its file properties, set Build Action to
Embedded Resource
- Grab a copy of related context connection string from the web project
Web.config
file. That should be something like
connectionString="metadata=res://\*/XXXXX.MyModel.csdl|
res://*/XXXXX.MyModel.ssdl|
res://*/XXXXX.MyModel.msl;
provider=ZZZZZ;provider connection string='AAAAA'"
- Transform that connection string in the web project config file for your deploy environment, say
Web.Debug.config
, in order to substitute the EDMX-generated SSDL file with your custom SSDL file:
connectionString="metadata=res://\*/XXXXX.MyModel.csdl|
res://*/YYYYY.MyModel.Debug.ssdl|
res://*/XXXXX.MyModel.msl;
provider=ZZZZZ;provider connection string='BBBBB'"
The last point could get tricky, at least in my experience, as the namespace of EDMX-generated SSDL resource was different from the namespace of my custom SSDL resource. In order to get the exact namespace for my custom resource, I ran a debug session in VS and checked the output of this.GetType().Assembly.GetManifestResourceNames()
in Immediate Window (thanks to stu432).
Also, I changed the connection string ='AAAAA'
part in order to match the DB server in deploy environment.