Entity Framework with Oracle

Asked

Viewed 845 times

3

I am trying to use EF, using Code Frist, along with an Oracle database, for this I am using the Nuget package Oracle.ManagedDataAccess.Entityframework, but whenever I try to run the Update-Database it gives the following error message:

System.Runtime.Serialization.Serializationexception: Type is not resolved for Member 'Oracle.ManagedDataAccess.Client.Oracleexception,Oracle.Manageddataaccess, Version=4.122.1.0, Culture=neutral, Publickeytoken=89b483f429c47342'.

At System.AppDomain.Docallback(Crossappdomaindelegate callBackDelegate) at System.Data.Entity.Migrations.Design.ToolingFacade.Run(Baserunner Runner) at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force) at System.Data.Entity.Migrations.Updatedatabasecommand.<>c__DisplayClass2. <. ctor>b__0() at System.Data.Entity.Migrations.Migrationsdomaincommand.Execute(Action command) Type is not resolved for Member 'Oracle.ManagedDataAccess.Client.Oracleexception,Oracle.Manageddataaccess, Version=4.122.1.0, Culture=neutral, Publickeytoken=89b483f429c47342'.

My context, my class and web.config are as follows:

public class MeuContext : DbContext
{
    public MeuContext()
        : base("OracleDbContext")
    {
    }

    public DbSet<GrupoProduto> GrupoProdutos { get; set; }

    protected override void OnModelCreating(DbModelBuilder dbModelBuilder)
    {
        base.OnModelCreating(dbModelBuilder);
        dbModelBuilder.HasDefaultSchema("atlas");
        dbModelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }
}

Class:

public class GrupoProduto
{
    [Key]
    public Guid GrupoProdutoId { get; set; }

    [Required]
    [StringLength(200)]
    [DisplayName("Nome")]
    public String Nome { get; set; }
}

Web.Config:

  <connectionStrings>
    <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=atlas;Password=atlas;Data Source=oracle" />
  </connectionStrings>
  <oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="oracle" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE))) " />
      </dataSources>
    </version>
  </oracle.manageddataaccess.client>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </providers>
  </entityFramework>

1 answer

3


Unfortunately I, even liking the Oracle database very much, advise against using EF Migrations with Oracle. They don’t give proper attention to your preview And there’s always a lot of problems like yours. I’ve worked with EF + Oracle for almost 2 years, and I’ve never been 100% happy. And apparently that scenario hasn’t changed much yet.

I recommend changing your strategy of Database Update for Change Scripts instead of Migrations.

If you are working with an application that will be hosted in VM, you can install the Oracle dll in GAC. But if you’re hosting in Paas - where you won’t have access to the host, you can only publish applications - it’s no longer an option.

C:\Windows\system32>cd E:\smn\packages\Oracle.ManagedDataAccess.12.1.021\lib\net40

C:\Windows\system32>e:

E:\smn\packages\Oracle.ManagedDataAccess.12.1.021\lib\net40>"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe" /i Oracle.ManagedDataAccess.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.33440
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

Snippet copied from that reply.

  • Just a comment, this DLL may be found inside the folder of nuget qnd if you install the ODP.Net library. Also I realized that it does not work with AutomaticMigrationsEnabled enabled, or I’m experiencing something wrong?

  • No, as I said, Oracle does not give due attention to its President. You Flfaz straight. Maybe it’s a bug. Try to report to Oracle, I think they will help more quickly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.