How to use Oracle Entity Framework with no config file

entity-framework entity-framework-6 odp.net oracle

Question

Is it possible to build an Entity Framework model using ODP.Net that connects to an existing database without needing any app.config settings?

I have experimented with numerous things.

I'm currently configuring DbConfiguration to:

    sealed class EntityFrameworkConfiguration : DbConfiguration
    {
        public static readonly DbConfiguration Instance = new EntityFrameworkConfiguration();

        EntityFrameworkConfiguration()
        {
            this.SetDefaultConnectionFactory(new OracleConnectionFactory());
            this.SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
        }
    }

    DbConfiguration.SetConfiguration(EntityFrameworkConfiguration.Instance);

I'm acing an exam.OracleConnection immediately into the framework of the EF.

Nevertheless, I either encounter issues with the SQL generated in SQL Server style (using double-quotes around table aliases), or I receive the following error:

An unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.dll

Additional information: 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.

Has anyone had success getting this to operate without messing up app.config?

1
3
9/6/2015 10:57:27 PM

Accepted Answer

ZZZ_tmp
1
9/7/2015 11:45:46 AM

Popular Answer

Yes. I had to add a call to in order to complete the transition from machine.config/app.config to code-based configuration.SetProviderFactory() .

public sealed class EntityFrameworkConfiguration : DbConfiguration
{
    public static readonly DbConfiguration Instance = new EntityFrameworkConfiguration();

    public EntityFrameworkConfiguration()
    {
        SetDefaultConnectionFactory(new OracleConnectionFactory());
        SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
        SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
    }
}

Also, I nicknamedDbConfiguration.SetConfiguration(EntityFrameworkConfiguration.Instance); because I had DbContexts in several assemblies that required to exchange this configuration during application starting.

Additionally, I have discovered that doing this successfully enables your program to get around theConfigurationErrorsException: The 'DbProviderFactories' section can only appear once per config file if you don't have access to the user's machine.config, fix it.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow