mysql缺少dotNet_asp.net core 缺少对UseMySQL的引用

asp.net core 缺少对UseMySQL的引用

最近在使用asp.net core的时候,数据库采用MySQL,出现了缺少对UseMySQL的引用。

具体代码如下:

Startup.csusing System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using Microsoft.AspNetCore.Builder;

using Microsoft.AspNetCore.Hosting;

using Microsoft.Extensions.Configuration;

using Microsoft.Extensions.DependencyInjection;

using SMS_ReciveDAL;

using Pomelo.EntityFrameworkCore.MySql;

using Microsoft.EntityFrameworkCore;

using MySql.Data.EntityFrameworkCore.Extensions;

namespace SMS_ReciveWeb

{

public class Startup

{

public Startup(IConfiguration configuration,IHostingEnvironment env)

{

var builder = new ConfigurationBuilder()

.SetBasePath(env.ContentRootPath)

.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)

.AddJsonFile("config.json", optional: true, reloadOnChange: true);

Configuration = builder.Build();

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)

{

var sqlConnectionString = Configuration.GetConnectionString("DataAccessMySqlProvider");

services.AddDbContext(options =>

options.UseMySQL(

sqlConnectionString,

b => b.MigrationsAssembly("AspNetCoreMultipleProject")

)

);

services.AddMvc();

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)

{

if (env.IsDevelopment())

{

app.UseDeveloperExceptionPage();

}

else

{

app.UseExceptionHandler("/Home/Error");

}

app.UseStaticFiles();

app.UseMvc(routes =>

{

routes.MapRoute(

name: "default",

template: "{controller=Home}/{action=Index}/{id?}");

});

}

}

}

出现这个错误的原因是:

缺少相应的引用。

解决方案:

增加对如下nuget包的引用,具体如下包:using Microsoft.EntityFrameworkCore;

using MySQL.Data.EntityFrameworkCore.Extensions;

我是在Visual Studio Code编辑器下开发的,关于如何添加nuget引用,可以参考下这篇文章:vscode 使用nuget

黄兵个人博客原创。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值