我指定了我在 Startup.cs 文件的实体项目中创建的上下文类和我为 connectionString 创建的 connectionString 数据。但是为什么我会收到这个错误?
错误消息:严重性代码描述项目文件行抑制状态错误 CS0311 类型“Microsoft.ApplicationInsights.Extensibility.Implementation.UserContext”不能用作泛型类型或方法“EntityFrameworkServiceCollectionExtensions.AddDbContext(IServiceCollection, Action, ServiceLifetime, ServiceLifetime)'。没有从“Microsoft.ApplicationInsights.Extensibility.Implementation.UserContext”到“Microsoft.EntityFrameworkCore.DbContext”的隐式引用转换。EntityFramework2 C:\Users\xsamu\source\repos\EntityFramework2\EntityFramework2\Startup.cs 29 活动
启动类:
namespace EntityFramework2
{
public class Startup
{
public Startup(IConfiguration configuration)
{
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)
{
services.AddControllersWithViews();
services.AddDbContext<UserContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DevConnection")));
}
// This method gets called by the runtime. Use this method to configure the HTTP …Run Code Online (Sandbox Code Playgroud)