title: ODP.NET and EF6 configuration on ASP.NET Core targeting .NET 4.7.2
body: <p>I can't get Entity Framework to use the Oracle Provider (ODP.NET) with my project. </p>
  
  <p>Setup:</p>
  
  <ul>
  <li>ASP.NET Core MVC 2.1 targeting .NET Framework 4.7.2</li>
  <li>EntityFramework 6.2</li>
  <li>ODP.NET 18.3 (Oracle.ManagedDataAccess and Oracle.ManagedDataAccess.EntityFramework)</li>
  </ul>
  
  <p>Although I'd prefer to use EF Core, I can't because Oracle isn't supporting EF Core yet, just .NET Core. </p>
  
  <p>The errors I'm receiving indicate that the application is trying to use the SQL Server driver. </p>
  
  <p>I can't find an example online for my scenario. Either its MVC5 with EF6/ODP.NET, or .NET Core examples with Oracle that don't have EF. </p>
  
  <p>My assumption is the problem lies in that in MVC5 configures it through web.config/app.config. I'm assuming I need to configure Oracle in start.cs but <strong>need the right syntax.</strong></p>
  
  <p>What I have coded for the Context class:</p>
  
  <pre><code>public class MainContext : DbContext
      {
          public MainContext(string connectionString) : base(connectionString)
          {
              Database.SetInitializer&lt;MainContext&gt;(null);
          }
  
          public virtual DbSet&lt;ApplicationSetting&gt; ApplicationSettings { get; set; }
      }
  </code></pre>
  
  <p>Then I created a factory:</p>
  
  <pre><code>public class MainContextFactory : IDbContextFactory&lt;MainContext&gt;
  
  {
      private readonly string _connectionString;
  
      public MainContextFactory(string connectionString)
      {
          _connectionString = connectionString;
      }
  
      public MainContext Create()
      {
          return new MainContext(_connectionString);
      }
  }
  </code></pre>
  
  <p>In Startup.cs I have:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
              services.AddMvc()
                  .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
  
              services.AddTransient&lt;IDbContextFactory&lt;MainContext&gt;&gt;(d =&gt;
                  new MainContextFactory(Configuration["ConnectionStrings:Primary"]));
  </code></pre>
  
  <p>I call this from my Repository project (targets .NET 4.7.2) and contains the MainContext:</p>
  
  <pre><code>public class ApplicationSettingRepository : BaseDbRepository, IApplicationSettingRepository
  {
      private readonly ILogger&lt;ApplicationSettingRepository&gt; _logger;
  
      public ApplicationSettingRepository(ILogger&lt;ApplicationSettingRepository&gt; logger, 
                                          IUserContext userContext,
                                          IDbContextFactory&lt;MainContext&gt; dbContextFactory) : base(userContext, dbContextFactory)
      {
          _logger = logger;
      }
  
      /// &lt;summary&gt;
      /// Get All Application Settings
      /// &lt;/summary&gt;
      public async Task&lt;List&lt;IApplicationSetting&gt;&gt; GetAllAsync()
      {
          var list = new List&lt;IApplicationSetting&gt;();
  
          using (var db = _contextFactory.Create())
          {
              list.AddRange(await db.ApplicationSettings.ToListAsync());
          }
  
          return list;
      }
  </code></pre>
  
  <p>which calls a base repository class:</p>
  
  <pre><code>public abstract class BaseDbRepository : IBaseRepository
  {
      protected IDbContextFactory&lt;MainContext&gt; _contextFactory;
  
      public IUserContext UserContext { get; set; }
  
      protected BaseDbRepository(IUserContext userContext, IDbContextFactory&lt;MainContext&gt; dbContextFactory)
      {
          UserContext = userContext;
          _contextFactory = dbContextFactory;
      }
  }
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>What do I need to update or add to make it call the ODP.NET provider?</li>
  <li>Is there a better approach to config? </li>
  </ol>