【发布时间】:2017-08-23 05:02:19
【问题描述】:
我是 EF Core 的新手,我正在尝试让它与我的 ASP.NET Core 项目一起使用。
当我尝试将DbContext 配置为使用配置中的连接字符串时,我在startup.cs 中收到上述错误。我正在关注this tutorial。
有问题的代码在startup.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using tracV2.models;
using tracV2.data;
namespace tracV2
{
public class Startup
{
// 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();
services.AddSingleton<IConfiguration>(Configuration);
string conn = Configuration.GetConnectionString("optimumDB");
services.AddDbContext<tracContext>(options => options.usesqlserver(conn));
}
UseSqlServer 方法如果我直接放到上下文中就可以识别:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace tracV2.data
{
public class tracContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("myrealconnectionstring");
}
我所有的在线研究都指出缺少参考,但我似乎无法找出我缺少哪一个 (see image)。
【问题讨论】:
-
同样的事情,intellisense 也找不到方法。
标签: asp.net-core entity-framework-core