Gil*_*rdo 30 .net c# asp.net entity-framework-core asp.net-core-mvc
我想实现实体框架7 MVC 6,并在此页上在这里它说做
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
Run Code Online (Sandbox Code Playgroud)
但对我来说,这个UseSqlServer
方法不可见?有谁知道如何让它可见?或者这是配置实体框架的旧方法?
我的startup.cs文件看起来像这样
using FluentValidation;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
namespace me.namespace.project
{
public class Startup
{
public static IConfiguration Configuration { get; set; }
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// entity framework
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<DataContext>();
}
}
}
Run Code Online (Sandbox Code Playgroud)
Tim*_*hko 39
安装Microsoft.EntityFrameworkCore.SqlServer 1.0.1包适用于我.Microsoft.EntityFrameworkCore的版本是1.1.0
Dav*_*idG 32
UseSqlServer
是命名空间中的扩展方法,Microsoft.Data.Entity
因此您需要在代码中导入它,如下所示:
using Microsoft.EntityFrameworkCore;
Run Code Online (Sandbox Code Playgroud)
编辑: 这个建议现在已经过时了(由于它是被接受的答案,我无法删除它).命名空间已经改变,您现在应该使用:
using Microsoft.EntityFrameworkCore;
Run Code Online (Sandbox Code Playgroud)
Ana*_*yal 28
由于已发布,因此已重命名程序集.作为EntityFrameworkCore的一部分,您现在需要添加以下的using语句
using Microsoft.EntityFrameworkCore;
Run Code Online (Sandbox Code Playgroud)
并且用于配置上下文的.UseSqlServer扩展方法将可用
小智 10
这是一个NuGet包问题
安装以下软件包及其正确版本
归档时间: |
|
查看次数: |
17425 次 |
最近记录: |