我是EF核心的新手,我正试图让它与我的asp.net核心项目一起工作.
startup.cs在尝试配置dbcontext以使用来自config的连接字符串时,我得到了上述错误.我正在关注本教程:https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro
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));
}
Run Code Online (Sandbox Code Playgroud)
usesqlserver如果我将其直接放入上下文中,则会识别该方法:
using System; …Run Code Online (Sandbox Code Playgroud)