You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用命名连接执行EF Scaffold失败:区域性标识无效报错

问题:EF Core从数据库生成脚手架模型时触发全球化文化错误

执行的命令序列

dotnet new webapi
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet user-secrets init
dotnet user-secrets set ConnectionStrings.Database "My Connection String"
dotnet ef dbcontext scaffold Name=ConnectionStrings.Database Microsoft.EntityFrameworkCore.SqlServer

报错信息

Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-us is an invalid culture identifier.

已尝试的无效解决方案

  • 修改项目文件中的<InvariantGlobalization>false</InvariantGlobalization>配置,未解决问题
  • 切换.NET版本至6、7、8,运行环境为Windows(该问题通常在Docker场景出现)

特殊现象

直接使用完整连接字符串替代Name=ConnectionStrings.Database参数执行脚手架命令时,可正常完成模型生成

内容的提问来源于stack exchange,提问作者greg-e

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 15:22:06