7

Using EF Core with Oracle.ManagedDataAccess.Core(2.18.3)

Not able to invoke the "options.UseOracle" method when trying to add DB context.

Compiler throws the error: 'DbContextOptionsBuilder' does not contain a definition for 'UseOracle' and no accessible extension method 'UseOracle' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?)

Please see code below, its the last line that does not compile, My nuget reference includes Oracle.ManagedDataAccess.Core(2.18.3)

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using EfGetStarted.AspNetCore.NewDb.Models;
using Microsoft.EntityFrameworkCore;
using Oracle.ManagedDataAccess.Client;

namespace EfGetStarted.AspNetCore.NewDb
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);



            var ora_conn = "User Id=xyz;Password=pwd;Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = ORA01)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = ora1)))";
            services.AddDbContext<BloggingContext>(options => options.UseOracle(ora_conn));


        }
Collin Barrett
  • 2,441
  • 5
  • 32
  • 53
frostwolfer
  • 93
  • 1
  • 1
  • 4
  • 3
    ODP.NET Core is just the ADO provider. Looks like the Oracle provider for EF Core [is not yet released](https://learn.microsoft.com/en-us/ef/core/providers/#oracle) – Ivan Stoev Oct 24 '18 at 16:50
  • Hmmm if I understand this correctly, Oracle.ManagedDataAccess.Core supports .Net Core but not EF Core, even though EF Core is a subset of .NET Core? – frostwolfer Oct 24 '18 at 21:04
  • EF Core is not subset of .Net Core. It's just a framework (library) and supports both Full Framework and .NET Core. But it requires its own [providers](https://learn.microsoft.com/en-us/ef/core/providers/) (libraries) – Ivan Stoev Oct 24 '18 at 21:30

2 Answers2

9

Try

PM> Install-Package Oracle.EntityFrameworkCore -Version 2.18.0-beta3
Thorsten
  • 135
  • 1
  • 9
1

I managed to install it after downloading oracle.entityframeworkcore.2.18.0-beta3.nupkg package, and adding 'IncludePrerelease':

Install-Package Oracle.EntityFrameworkCore -IncludePrerelease -Source C:\Temp\

Everything works fine but when trying to get records by id, for example: Table.SingleOrDefaultAsync(m => m.Id == id); I get error: (sql command not properly ended)

Ivica Buljević
  • 150
  • 1
  • 8