I am having a hard time working with EF and Oracle. Earlier, I have developed an app that use EF and Oracle and have ran well. I installed the ODAC in local computer (GAC) that contains Oracle.ManagedDataAccess and Oracle.ManagedDataAccess.EntityFramework.
This time I develop an app that using EF and Oracle too, but I just want to use the NuGet package of Oracle.ManagedDataAccess and Oracle.ManagedDataAccess.EntityFramework.
this is my app.config
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
<provider invariantName="Oracle.ManagedDataAccess.Client"
type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="myDataSource" descriptor="(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = host)(PORT = port))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))"/>
</dataSources>
</version>
</oracle.manageddataaccess.client>
<connectionStrings>
<add name="myConnectionString" providerName="Oracle.ManagedDataAccess.Client"
connectionString="User Id=user_id;Password=password;Data Source=myDataSource"/>
</connectionStrings>
</configuration>
I tried to run a simple query:
pulic IEnumerable<int> GetIDs()
{
var context = new MyDbContext();
var sql = "SELECT ID FROM SOME_TABLE";
return context.Database.SqlQuery<Payable>(sql.ToString());
}
And it throws exception:
Oracle.ManagedDataAccess.Client.OracleException: ORA-01918: user 'dbo' does not exist
Then using this post I add this to my code:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("SCHEMA_NAME");
}
Well, it run well in my development environment. And when I try to run it in the server, which didn't have ODAC installed, it throws this exception.
Oracle.ManagedDataAccess.Client.OracleException: ORA-00955: name is already used by an existing object
Well, it's pretty weird, and I am really confused. Please help.
The Problem: You are trying to create tables into the database that it already exists from the previous migration.
The Solution: Delete every thing from the database first and then make your migrations.
There is an oracle query that helps you to make that it's in this link How to drop all user tables?