这个错误并不总是产生一些东西,当数据库在服务器上时如果数据库在本地机器上没有问题 我在sql数据库和mysql数据库中找到了它 DbContext 注册为 ServiceLifetime.Transient 但问题仍然出现在服务器上的数据库
当我尝试在
user.RoleNames = await userManager.GetRolesAsync(user);
中为用户获取角色时出现问题
protected async System.Threading.Tasks.Task Load()
{
var securityGetUserByIdResult = await Security.GetUserById($"{Id}");
user = securityGetUserByIdResult;
var securityGetRolesResult = await Security.GetRoles();
roles = securityGetRolesResult;
}
然后我调用 GetUserById
public async Task<ApplicationUser> GetUserById(string id)
{
var user = await userManager.FindByIdAsync(id);
if (user != null)
{
context.Entry(user).Reload();
user.RoleNames = await userManager.GetRolesAsync(user);
}
return await Task.FromResult(user);
}
我尝试了多种解决方案,比如 semaphoreSlim 没有解决问题
• EF Core DbContext 缓存结果包括具有动态全局过滤器的实体
• 如何通过选项配置在自定义私有DbContext包中设置Azure默认TenantId
• ASP.NET Core HTTP 记录器中间件导致“在上一个操作完成之前在此上下文实例上启动了第二个操作”
• Blazor 服务器端的 .Net Core DbContext 线程问题
• 带有语句体的 lambda 表达式不能用 Entity Framework 转换为表达式树
• 如何将 dbFactory 与我的 dbContext 基类而不是其派生类一起使用
• DbContext 中的 DbSet 为空 .NET Core 6
• Azure 多个 DbContext 在具有不同的连接字符串时最终在同一个数据库中
• ProjectReference with asp.net core 5
• 为什么这个[1+2]不被接受? - ANTLR4 语法错误
• NuGet - NU5131: nuspec文件中声明的引用没有被打包。
• 错误。"找不到源自dbcontext的可构造类型"(Visual Studio 2019和EF 6工具)