IManifestTokenResolver for Database First Model?

落爺英雄遲暮 提交于 2020-01-11 07:22:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!