错误 CS1061:“DbContextOptionsBuilder”不包含“UseMySql”的定义

时间:2021-05-08 12:57:51

标签: c# mysql asp.net razor

大家好,我正在尝试连接到数据库,但由于某种原因它无法正常工作。我收到此错误 error CS1061: 'DbContextOptionsBuilder' does not contain a definition for 'UseMySql' and no accessible extension method 'UseSqlServer' accepting a first argument of type 'DbContextOptionsBuilder' could be found 我使用 asp.net Razor 页面。 这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using virtualwb.Models;
using Pomelo.EntityFrameworkCore.MySql;

namespace virtualwb
{
    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.AddRazorPages();
            services.AddDbContext<DatabaseContext>(options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));
        }

0 个答案:

没有答案