IManifestTokenResolver for Database First Model?
Asked Answered
C

0

1

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?

Converted answered 22/10, 2015 at 13:53 Comment(2)
I was wondering if you ever found a solution to this? I need to do the same and just can't find a way to configure it in code.Reform
Did you attach your DbConfiguration class to your object context? You can do it by adding this attribute. [DbConfigurationType(typeof(MyDbConfiguration))]Braunschweig

© 2022 - 2024 — McMap. All rights reserved.