dbcontext mysql_mysql – ‘DbContextOptionsBuilder’不包含’UseSqlServer’的定义
我正在嘗試使用C#在VS 2015 Pro(Update 3)中創(chuàng)建Web API并以.NET Core為目標(biāo).
無(wú)論如何,在教程中,我必須“使用依賴注入注冊(cè)我的上下文” – 所以我必須將以下行添加到Startup.cs文件的ConfigureServices部分:
var connection = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext< Models.PropWorxContext > (options => options.UseSqlServer(connection));;
但是,VS給了我以下錯(cuò)誤:
錯(cuò)誤CS1061’DbContextOptionsBuilder’不包含’UseSqlServer’的定義,并且沒(méi)有可以找到接受類型’DbContextOptionsBuilder’的第一個(gè)參數(shù)的擴(kuò)展方法’UseSqlServer'(您是否缺少using指令或程序集引用?)
有什么想法嗎?
這就是整個(gè)Startup.cs文件的樣子:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace PropWorxAPI
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
var connection = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext< Models.PropWorxContext > (options => options.UseSqlServer(connection));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
}
}
}
我還使用包管理器添加了MySQL包,因此我的project.json文件包含以下條目:
*"MySql.Data.EntityFrameworkCore":?"7.0.6-IR31"*
任何關(guān)于我出錯(cuò)的提示都會(huì)非常感激,因?yàn)槲一艘徽鞎r(shí)間試圖解決這個(gè)問(wèn)題:(謝謝……
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的dbcontext mysql_mysql – ‘DbContextOptionsBuilder’不包含’UseSqlServer’的定义的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql my.cnf参数配置_MyS
- 下一篇: linux系统下的mysqlgt;abo