7

将 EF Core 与 Oracle.ManagedDataAccess.Core(2.18.3) 一起使用

尝试添加数据库上下文时无法调用“options.UseOracle”方法。

编译器抛出错误:“DbContextOptionsBuilder”不包含“UseOracle”的定义,并且找不到接受“DbContextOptionsBuilder”类型的第一个参数的可访问扩展方法“UseOracle”(您是否缺少 using 指令或程序集引用?)

请看下面的代码,它最后一行没有编译,我的 nuget 参考包括 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));


        }
4

2 回答 2

8

尝试

PM> Install-Package Oracle.EntityFrameworkCore -Version 2.18.0-beta3
于 2019-04-04T08:11:09.450 回答
1

在下载 oracle.entityframeworkcore.2.18.0-beta3.nupkg 包并添加“IncludePrerelease”后,我设法安装了它:

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

一切正常,但是当尝试通过 id 获取记录时,例如:Table.SingleOrDefaultAsync(m => m.Id == id); 我收到错误:(sql 命令未正确结束)

于 2019-04-09T15:48:44.587 回答