We need an option to set the ProviderManifestToken in code for a Database First Model in order to override the value from the EDMX, which defaults to "2012" for SQL Server 2012 in our particular case.
What we've tried so far: As described in this post we decorated our context class with the DbConfigurationType attribute, our derived class looks exactly the same as in that post.
internal sealed class MyDbConfiguration : DbConfiguration
{
public MyDbConfiguration()
{
//this.AddDependencyResolver(new SingletonDependencyResolver<IManifestTokenResolver>(new ManifestTokenService()));
this.SetManifestTokenResolver(new ManifestTokenService());
}
}
As you can see, we tried 2 different things here, AddDependencyResolver and SetManifestTokenResolver.
When we start the application program execution enters the constructor of MyDbConfiguration - and that's it, the dependency resolver itself
internal sealed class ManifestTokenService : IManifestTokenResolver
{
private const string SqlServerManifestToken = @"2005";
private static readonly IManifestTokenResolver DefaultManifestTokenResolver = new DefaultManifestTokenResolver();
/// <inheritdoc />
public string ResolveManifestToken(DbConnection connection)
{
if (connection is SqlConnection)
{
return SqlServerManifestToken;
}
return DefaultManifestTokenResolver.ResolveManifestToken(connection);
}
}
is never invoked so it seems we've reached a dead end here. Has anyone had the same problem and found a solution?
来源:https://stackoverflow.com/questions/33282739/imanifesttokenresolver-for-database-first-model