none
Entity Framework with Oracle AND SQL RRS feed

  • Question

  • Is it possible for a MVC application that uses Entity Framework 6 to get data from both a SQL database and an Oracle database?  I have not been able to overcome the limitation of having only one DbConfiguration class being loaded.  A DbConfiguration class is need to set the SetDefaultConnectionFactory to SQL and one to set it to Oracle.
    Wednesday, September 7, 2016 6:08 PM

Answers

  • So after a long road of test projects and some excellent advice from David I have finally figured out what I was missing.  You can have as many DbContext classes as you would like in an application but only one DbConfiguration class.  In the DbConfiguration class you can set up all of the providers and factories that you need.  Following the samples I listed in my previous comments add this new class:

    using Oracle.ManagedDataAccess.Client;
    using Oracle.ManagedDataAccess.EntityFramework;
    using System.Data.Entity;
    
    namespace WebTest
    {
        public class CodeConfig : DbConfiguration
        {
            public CodeConfig()
            {
                SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
                SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
                SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
            }
        }
    }

    Now the Oracle and Sql Server providers are available to the DbContext classes.  Hopefully MS will add an example or some documentation around this to make it clearer.

    Tuesday, September 13, 2016 12:17 PM

All replies

  • Is it possible for a MVC application that uses Entity Framework 6 to get data from both a SQL database and an Oracle database?  I have not been able to overcome the limitation of having only one DbConfiguration class being loaded.  A DbConfiguration class is need to set the SetDefaultConnectionFactory to SQL and one to set it to Oracle.

    To me, it seems that you are drinking the MS Kool Aid where you are trying to use EF up in the MVC controller directly. If you are doing that, can be bad news for you.

    What you should be doing is some kind of SoC.

    https://en.wikipedia.org/wiki/Separation_of_concerns

    In Soc, I mean you should be using a Web API for EF and MS SQL Server and a Web API for EF and Oracle, a separation of the two models and the DBContext.

    You can achieve the same thing if using a DAL with the DAL having MS SQL Server and EF model and Oracle and EF model that the MVC controller can call, which is a another way to implement separation.

     

    Wednesday, September 7, 2016 8:54 PM
  • Currently the solution structure is pretty well separated into layers already.  I have a separate project for the web site, repository and data access.  The web site calling into the repository which calls either the Oracle or Sql Server DAL.  Which ever one is called first seems to set the DbConfiguration for the whole application so the other one fails. 

    Thursday, September 8, 2016 8:40 PM
  • Do you use different DbContext types for SQL Server and Oracle?

    There's a similar thread here, but with SQL Server and SQL Compact:

    http://stackoverflow.com/questions/20354083/ef6-and-multiple-configurations-sql-server-and-sql-server-compact

    David


    David http://blogs.msdn.com/b/dbrowne/

    Thursday, September 8, 2016 8:55 PM
  • SQL Server and Oracle require different DbConfiguration classes:

    SQL Server:

     public class SqlDbConfig : DbConfiguration
     {
           public SqlDbConfig()
           {
                this.SetDefaultConnectionFactory(new System.Data.Entity.Infrastructure.SqlConnectionFactory());
           }
     }
    

    Oracle:

    public class OracleDbConfig : DbConfiguration
    {
            public OracleDbConfig()
            {
                SetDefaultConnectionFactory(new OracleConnectionFactory());
                SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);            
                SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
            }
    }
    If they had the same setting I could just pass a different connection string.  It seems that once the DbConfiguration is set its now a Singleton and is read-only.  

    Friday, September 9, 2016 1:22 PM
  • If they had the same setting I could just pass a different connection string.  It seems that once the DbConfiguration is set its now a Singleton and is read-only.  

    Well, I have used two different EF models in the same DAL in the past using two different VS folders/namespaces to separate the two, and there was no sharing of anything between the two EF models. Also, I was using and continue to use the EF DB First approach, which simplifies using EF. You start using Code First, then you have a nightmare on your hands.

    Friday, September 9, 2016 2:04 PM
  • Right.  The issue here is that you don't want to use the "DefaultConnectionFactory".  But that's the only way EF knows how to instantiate your database connections if you use the no-arg DbContext constructor.  The easiest thing is to just use the DbContext constructor that takes a DbConnection object.  Then you are in charge of creating the appropriate connection type.

    And apparently the DbModelBuilder cache is smart enough to not attempt to reuse a DbCompiledModel across different providers.  So even if you use the same DbContext for both, you just have to branch in OnModelCreating to account for any differences.

    using Oracle.ManagedDataAccess.Client;
    using System;
    using System.Collections.Generic;
    using System.Data.Common;
    using System.Data.Entity;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace efTestOracle
    {
    
        class Customer
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }
    
        class MyDb : DbContext
        {
            public MyDb(DbConnection con) : base(con, true)
            {
    
            }
            public DbSet<Customer> Customers { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                if (this.Database.Connection is OracleConnection)
                {
                    modelBuilder.HasDefaultSchema("HR");
                }
                else if (this.Database.Connection is SqlConnection)
                {
                    modelBuilder.HasDefaultSchema("dbo");
                }
                base.OnModelCreating(modelBuilder);
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                using (var db = new MyDb(new SqlConnection("Server=.;Database=tempdb;Integrated Security=true")))
                {
                    var q = db.Customers.Take(1);
                    Console.WriteLine(q.ToString());
                }
    
                using (var db = new MyDb(new OracleConnection("Data Source=//oracle/xe;User Id=system;Password=xxxx")))
                {
                    var q = db.Customers.Take(1);
                    Console.WriteLine(q.ToString());
                }
    
                using (var db = new MyDb(new SqlConnection("Server=.;Database=tempdb;Integrated Security=true")))
                {
                    var q = db.Customers.Take(1);
                    Console.WriteLine(q.ToString());
                }
            }
        }
    }

    David


    David http://blogs.msdn.com/b/dbrowne/



    Friday, September 9, 2016 2:51 PM
  • I think I am missing something in the design.  The actual error I am getting is this:

    • An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code.
      Additional information: An instance of 'SqlDbConfig' was set but this type was not discovered in the same assembly as the 'VcisDataStoreContext' context. Either put the DbConfiguration type in the same assembly as the DbContext type, use DbConfigurationTypeAttribute on the DbContext type to specify the DbConfiguration type, or set the DbConfiguration type in the config file. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information.

    The solution structure is broken out as follows:

    • Data.Application (Sql Server Data)
    • Data.DataStore (Oracle Data)
    • Domain.ViewModel
    • Repository
    • Web

    The first thing that loads is the menu adapter that loads the menu getting the Sql data.

    public MenuItemAdapter(IOptions<AppSettings> appOptions)
    {
        var connection = new SqlConnection(appOptions.Value.VcisApplicationConnection);
        var context = new VcisAppContext(connection, true);
        this.repository = new MenuRepository(context);
        this.mapper = Mapper.Instance;
    }

    The next part of the page loads getting some Fund data which is in Oracle.

    public FundAdapter(IOptions<AppSettings> appOptions)
    {
        var dataStoreConn = new OracleConnection(appOptions.Value.VcisDataStoreConnection);
        var dataStoreContext = new VcisDataStoreContext(dataStoreConn, true);
                
        this.repository = new FundRepository(dataStoreContext);           
        this.mapper = Mapper.Instance;
    }

    The error happens when the class is created.

    [DbConfigurationType(typeof(OracleDbConfig))]
    public partial class VcisDataStoreContext : DbContext
    {
        public VcisDataStoreContext(DbConnection dbConnection, bool contextOwnsConnection) : base(dbConnection, contextOwnsConnection) { }
    
    ...
    
     protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                if (this.Database.Connection is OracleConnection)
                {
                    modelBuilder.HasDefaultSchema("VCISDB");
                }

    Do I need to combine the two DbContext classes into one and use an IF statement to load the proper mappings?  If I do that how do the configuration properties specific to Oracle get loaded?

    Thank you for assisting with this.

    Friday, September 9, 2016 8:21 PM
  • >Do I need to combine the two DbContext classes into one and use an IF statement to load the proper mappings?

    No.  Strip it down to a small repro?

    David


    David http://blogs.msdn.com/b/dbrowne/

    Friday, September 9, 2016 8:50 PM
  • I created a small app that has the same problem.  If Sql is called first Oracle does not work, if Oracle is called first Sql will work though.

    project.json

    {
      "version": "1.0.0-*",
      "dependencies": {
        "EntityFramework": "6.1.3",
        "Oracle.ManagedDataAccess": "12.1.24160419",
        "Oracle.ManagedDataAccess.EntityFramework": "12.1.2400",
        "System.Data.Common": "4.1.0",
        "System.Data.SqlClient": "4.1.0",
        "System.Runtime": "4.1.0"
      },
    
      "frameworks": {
        "net46": {
          "frameworkAssemblies": {
            "System.Data": "4.0.0.0"
          }
        }
      },
      "buildOptions": {
        "emitEntryPoint": true
      }
    }


    Program.cs

    using DataTest.OracleData;
    using DataTest.SqlData;
    using Oracle.ManagedDataAccess.Client;
    using System;
    using System.Data.SqlClient;
    using System.Linq;
    
    namespace DataTest
    {
        public class Program
        {
            public static void Main(string[] args)
            {                                 
                Console.WriteLine("Press S for Sql first or O for Oracle first or E to exit: ");
                char resultKey = Console.ReadKey().KeyChar;
                
                while (Convert.ToString(resultKey).ToLower() != "e")
                {                                
                    if (Convert.ToString(resultKey).ToLower() == "s")
                    {
                        TestSqlServer();
                        TestOracle();
                    }
                    else if (Convert.ToString(resultKey).ToLower() == "o")
                    {
                        TestOracle();
                        TestSqlServer();
                    }
                    
                    Console.WriteLine("Press S for Sql first or O for Oracle first or E to exit: ");
                    resultKey = Console.ReadKey().KeyChar;
                }           
            }
            private static void TestSqlServer()
            {
                Console.WriteLine(" ");
                Console.WriteLine("Test SQL Server conection...");
                try
                {
                    //Get the SQL Items
                    string sqlConnString = "Data Source=TESTSQL;Initial Catalog=TEST;User Id=TESTApp; password=TEST;Pooling=False;MultipleActiveResultSets=True;Application Name=EntityFramework";
                    var sqlConnection = new SqlConnection(sqlConnString);
                    SqlDataContext sqlContext = new SqlDataContext(sqlConnection, true);
                    IQueryable<MenuItem> sqlMenuItems = from m in sqlContext.MenuItems select m;
                    Console.WriteLine("Sql Menu Items: " + sqlMenuItems.Count().ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
    
            }
    
            private static void TestOracle()
            {
                Console.WriteLine("");
                Console.WriteLine("Test Oracle connection...");
                try
                {
                    string oracleConnString = "User Id=TEST;Password=TEST;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ORACLSETEST)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=TESTDev)));";
                    var oracleConnection = new OracleConnection(oracleConnString);
                    OracleDataContext oracleContext = new OracleDataContext(oracleConnection, true);
                    IQueryable<DMENU> oracleMenuItems = from m in oracleContext.DMENUs select m;
                    Console.WriteLine("Oracle Menu Items: " + oracleMenuItems.Count().ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }


    In the OracleData folder...

    DMENU.cs

    namespace DataTest.OracleData
    {
        using System.ComponentModel.DataAnnotations;
        using System.ComponentModel.DataAnnotations.Schema;
    
        [Table("VCISDB.DMENU")]
        public partial class DMENU
        {
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
            public DMENU()
            {            
            }
    
            [Key]
            [DatabaseGenerated(DatabaseGeneratedOption.None)]
            public short DM_ID { get; set; }
            public short? DM_PARENTID { get; set; }      
            [StringLength(100)]
            public string DM_TEXT { get; set; }
            public byte? DM_SORTORDER { get; set; }
            [StringLength(200)]
            public string URL { get; set; }
        }
    }

    OracleDataContext.cs

    namespace DataTest.OracleData
    {
        using System.Data.Common;
        using System.Data.Entity;
    
        [DbConfigurationType(typeof(OracleDbConfig))]
        public partial class OracleDataContext : DbContext
        {
            public OracleDataContext(DbConnection dbConnection, bool contextOwnsConnection) : base(dbConnection, contextOwnsConnection) { }
            public virtual DbSet<DMENU> DMENUs { get; set; }
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
               
            }
        }
    }
    

    OracleDbConfig.cs

    using Oracle.ManagedDataAccess.Client;
    using Oracle.ManagedDataAccess.EntityFramework;
    using System.Data.Entity;
    
    namespace DataTest.OracleData
    {
        public class OracleDbConfig : DbConfiguration
        {
            public OracleDbConfig()
            {
                SetDefaultConnectionFactory(new OracleConnectionFactory());
                SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
                SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
            }
        }
    }

    In the SqlData folder:

    MenuItem.cs

    namespace DataTest.SqlData
    {
        using System.ComponentModel.DataAnnotations;
        using System.ComponentModel.DataAnnotations.Schema;
    
        [Table("MenuItem")]
        public partial class MenuItem
        {
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
            public MenuItem()
            {          
            }
           
            public int MenuItemId { get; set; }
            [Required]
            [StringLength(100)]
            public string Title { get; set; }
    
            [StringLength(500)]
            public string Url { get; set; }
    
            public int? SortOrder { get; set; }
    
            public int? ParentMenuItemId { get; set; }
    
        }
    }
    

    SqlDataContext.cs

    using System.Data.Common;
    using System.Data.Entity;
    
    namespace DataTest.SqlData
    {
        [DbConfigurationType(typeof(SqlDbConfig))]
        public class SqlDataContext : DbContext
        {
            public SqlDataContext(DbConnection dbConnection, bool contextOwnsConnection) : base(dbConnection, contextOwnsConnection) { }
    
            public virtual DbSet<MenuItem> MenuItems { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {                        
            }
        }
    }
    

    SqlDbConfig.cs

    using System.Data.Entity;
    
    namespace DataTest.SqlData
    {
        public class SqlDbConfig : DbConfiguration
        {
            public SqlDbConfig()
            {
                this.SetDefaultConnectionFactory(new System.Data.Entity.Infrastructure.SqlConnectionFactory());
            }
        }
    }
    

    The error message is:

    Unable to determine the provider name for provider factory of type 'Oracle.ManagedDataAccess.Client.OracleClientFactory'. Make sure that the ADO.NET provider is
     installed or registered in the application config.

    Monday, September 12, 2016 12:22 PM
  • It appears you are using an .xproj, targeting .NET 4, correct?

    I think you are missing the configuration information that registers these types for Oracle.

    I created a console .xproj and added all that code, and it reproduced the failure until I manually created a DataTest.exe.config in the output directory and pasted in all the configuration that is created in a .csproj when you add the Oracle NuGet package.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Monday, September 12, 2016 2:10 PM
  • I was able to get both working following your example with the .config file.  The application that I am building is a web app so I created a base .NET Core web site to test this in, then added the two folders OracleData and SqlData to the project.

    The project.json file

    {
      "dependencies": {
        "EntityFramework": "6.1.3",
        "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
        "Microsoft.AspNetCore.Diagnostics": "1.0.0",
        "Microsoft.AspNetCore.Mvc": "1.0.0",
        "Microsoft.AspNetCore.Razor.Tools": {
          "version": "1.0.0-preview2-final",
          "type": "build"
        },
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
        "Microsoft.AspNetCore.StaticFiles": "1.0.0",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
        "Oracle.ManagedDataAccess.EntityFramework": "12.1.2400",
        "System.Data.Common": "4.1.0",
        "System.Data.SqlClient": "4.1.0"
      },
    
      "tools": {
        "BundlerMinifier.Core": "2.0.238",
        "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
      },
      "frameworks": {
        "net46": {
          "dependencies": {
    
          }
        }
      },
    
      "buildOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true
      },
    
      "runtimeOptions": {
        "configProperties": {
          "System.GC.Server": true
        }
      },
    
      "publishOptions": {
        "include": [
          "wwwroot",
          "Views",
          "Areas/**/Views",
          "appsettings.json",
          "web.config"
        ]
      },
    
      "scripts": {
        "prepublish": [ "bower install", "dotnet bundle" ],
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
      }
    }


    HomeController.cs

    using Microsoft.AspNetCore.Mvc;
    using Oracle.ManagedDataAccess.Client;
    using System;
    using System.Data.SqlClient;
    using System.Linq;
    using WebTest.OracleData;
    using WebTest.SqlData;
    using WebTest.ViewModel;
    
    namespace WebTest.Controllers
    {
        public class HomeController : Controller
        {
            public IActionResult Index()
            {
                var vm = new TestVM();
    
                vm.SqlResults = TestSqlServer();
                vm.OracleResults = TestOracle();
                          
                return View(vm);
            }
    
            public IActionResult About()
            {
                ViewData["Message"] = "Your application description page.";
    
                return View();
            }
    
            public IActionResult Contact()
            {
                ViewData["Message"] = "Your contact page.";
    
                return View();
            }
    
            public IActionResult Error()
            {
                return View();
            }
    
            private string TestSqlServer()
            {
                string message = "";
                message = "Test SQL Server conection...";
                try
                {
                    //Get the SQL Items
                    string sqlConnString = "Data Source=NEA-SQLDB4;Initial Catalog=VCIS;User Id=VcisWebApp; password=vcis4nea;Pooling=False;MultipleActiveResultSets=True;Application Name=EntityFramework";
                    var sqlConnection = new SqlConnection(sqlConnString);
                    var sqlContext = new SqlDataContext(sqlConnection, true);
                    IQueryable<MenuItem> sqlMenuItems = from m in sqlContext.MenuItems select m;
                    message = message + "Sql Menu Items: " + sqlMenuItems.Count().ToString();
                }
                catch (Exception ex)
                {
                    message = message + ex.Message;
                }
                return message;
            }
    
            private string TestOracle()
            {
                string message = "";
                message = "Test Oracle conection...";
                try
                {
                    string oracleConnString = "User Id=vcis;Password=nea;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=nea-oracletst)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=NEADev)));";
                    var oracleConnection = new OracleConnection(oracleConnString);
                    oracleConnection.Open();
                    var oracleContext = new OracleDataContext(oracleConnection, true);
                    IQueryable<DMENU> oracleMenuItems = from m in oracleContext.DMENUs select m;
                    message = message + "Oracle Menu Items: " + oracleMenuItems.Count().ToString();
                }
                catch (Exception ex)
                {
                    message = message + ex.Message;
                }
                return message;
            }
        }
    }

    Where would I put the configuration data for the Oracle provider?  

    Thanks

    Monday, September 12, 2016 5:55 PM
  • >Where would I put the configuration data for the Oracle provider?  

    I think it goes in a web.config file, or higher in the traditional .NET config file hierarchy.  The .NET Core web site project doesn't really help you with this, but it shouldn't prevent it either.  If you're writing for .NET 4.6, it will look for configuration in the web.config at runtime.

    If you are only targeting .NET 4.6.1 you may want to just use the traditional ASP.NET project in VS instead.

    David


    David http://blogs.msdn.com/b/dbrowne/


    Monday, September 12, 2016 6:05 PM
  • David,

    Thank you for your great support in helping me with figuring this out.  I took your advice and started with a traditional ASP.NET template and worked from there.  The underlying issue was that there can only be ONE class that inherits from DbConfiguration in any of the projects being use.  

    Using this link: http://www.entityframeworktutorial.net/entityframework6/code-based-configuration.aspx 

    Note: EF does not support having multiple configuration classes used in the same AppDomain. If you use this attribute, to set different configuration classes for two contexts, then an exception will be thrown.

    The solution was to add the entityFramework section in the web.config

    <entityFramework

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v13.0" /> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" /> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework>

    So this works for traditional ASP.Net, now I am working on how to get this to work with using the json configuration file that the newer ASP.NET uses.

    Monday, September 12, 2016 9:04 PM
  • So after a long road of test projects and some excellent advice from David I have finally figured out what I was missing.  You can have as many DbContext classes as you would like in an application but only one DbConfiguration class.  In the DbConfiguration class you can set up all of the providers and factories that you need.  Following the samples I listed in my previous comments add this new class:

    using Oracle.ManagedDataAccess.Client;
    using Oracle.ManagedDataAccess.EntityFramework;
    using System.Data.Entity;
    
    namespace WebTest
    {
        public class CodeConfig : DbConfiguration
        {
            public CodeConfig()
            {
                SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
                SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
                SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
            }
        }
    }

    Now the Oracle and Sql Server providers are available to the DbContext classes.  Hopefully MS will add an example or some documentation around this to make it clearer.

    Tuesday, September 13, 2016 12:17 PM
  • So after a long road of test projects and some excellent advice from David I have finally figured out what I was missing.  You can have as many DbContext classes as you would like in an application but only one DbConfiguration class.  In the DbConfiguration class you can set up all of the providers and factories that you need.  Following the samples I listed in my previous comments add this new class:

    using Oracle.ManagedDataAccess.Client;
    using Oracle.ManagedDataAccess.EntityFramework;
    using System.Data.Entity;
    
    namespace WebTest
    {
        public class CodeConfig : DbConfiguration
        {
            public CodeConfig()
            {
                SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
                SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
                SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
            }
        }
    }

    Now the Oracle and Sql Server providers are available to the DbContext classes.  Hopefully MS will add an example or some documentation around this to make it clearer.

    I guess this only applies to when one is using the fly paper code first approach.

    Tuesday, September 13, 2016 2:19 PM