options.UseOracle()在EF Core中不可用

时间:2018-10-24 15:01:44

标签: c# asp.net-core entity-framework-core oracle.manageddataaccess

将EF Core与Oracle.ManagedDataAccess.Core(2.18.3)结合使用

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

编译器抛出错误:'DbContextOptionsBuilder'不包含'UseOracle'的定义,并且找不到可访问的扩展方法'UseOracle'接受类型为'DbContextOptionsBuilder'的第一个参数(是否缺少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));


        }

2 个答案:

答案 0 :(得分:2)

尝试

PM> Install-Package Oracle.EntityFrameworkCore -Version 2.18.0-beta3

答案 1 :(得分:0)

下载oracle.entityframeworkcore.2.18.0-beta3.nupkg软件包并添加'IncludePrerelease'之后,我设法安装了它:

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

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