UPDATE: I wrote a tip on my blog in my Tips Series to cover this in a little more detail.
--
Well as you guessed the key to this is the ProviderManifestToken.
The EF uses this to establish what Database Types are available.
Obviously if the SSDL (Storage or Database Model) portion of the EDMX references types not supported on a particular version of SQL server you will need to modify not just the ProviderManifestToken, but also replace all the references to types not supported on the target version too.
One approach to this is to treat the SSDL portion of the file as something that can be swapped out at runtime.
To do this you need to extract the CSDL/MSL/SSDL into files rather than having them embedded in the assembly as is standard:
- Right click on the designer
canvas
- Select Properties
- Set 'Metadata Artifact Processing' to 'Copy to Output Directory'
- Build
- Now you need to copy the SSDL file (in bin\debug), and modify it to work with SQL2005, by replacing references to DateTime2 with DateTime etc.
- Then at runtime when constructing an object context you need to manually create the ConnectionString, making it point to the correct SSDL...
And use it like this:
var connStr = @"metadata=.\model.csdl|.\modelSQL2005.ssdl|.\model.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=.\SQLEXPRESS;
Initial Catalog=TipsDatabase;
Integrated Security=True;
MultipleActiveResultSets=True
"";
using (var ctx = new MyContext(connStr))
{
}
I know this isn't ideal, but at least it gives you a workable solution.
Hope this helps
Alex