flurry 2023-12-10 19:05
浏览 284
已结题

Net8 EFCore Mysql 连接 The service collection cannot be modified because it is read-only”

我根据你的文章 Net8 EFCore Mysql 连接
//注意:在动态对EntityFrameworkCore中间件进行实例化时,必须使用“AddDbContextPool” 内置方法替换“AddDbContext”内置方法,
//否则就会出现异常:“System.InvalidOperationException: The service collection cannot be modified because it is read-only”

我把AddDbContext改为AddDbContextPool 还是这个错误 请问怎么解决

    builder.Services.AddDbContextPool<SqlContext>(options =>
    {
        var serverVersion = ServerVersion.AutoDetect(sqlConnection);  //mysql版本: {8.2.0-mysql}
        options.UseMySql(sqlConnection, serverVersion);

    });

  • 写回答

1条回答 默认 最新

  • flurry 2023-12-10 19:40
    关注

    位置放错了 真傻

    评论

报告相同问题?

问题事件

  • 系统已结题 12月18日
  • 创建了问题 12月10日