小编el *_*adi的帖子

CS0311 C# 该类型不能用作泛型类型或方法中的类型参数“TContext”。实体框架核心

我指定了我在 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)

c# entity-framework-core ef-fluent-api

3
推荐指数
1
解决办法
3333
查看次数

标签 统计

c# ×1

ef-fluent-api ×1

entity-framework-core ×1