5.9K Star 11.7K Fork 4K

GVPdotNET China / Furion

 / 详情

DefaultDbContext 不能识别

已完成
创建于  
2021-01-14 21:05

Furion 版本号

1.7.0 -> 1.10.3


Web 项目类型

  • WebApi
  • Mvc
  • Razor Pages
  • Blazor Server

描述你的问题

发生了什么?
脚手架安装 1.7.0


异常堆栈信息

System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, IDbContextOptions contextOptions, DbContext context)
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[TService](IInfrastructure1 accessor) at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure1 accessor)
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.get_Dependencies()
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.Microsoft.EntityFrameworkCore.Storage.IDatabaseFacadeDependenciesAccessor.get_Dependencies()
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetFacadeDependencies(DatabaseFacade databaseFacade)


代码或代码仓库

注入了 DefaultDbContext 并且
public void ConfigureServices(IServiceCollection services)
{
services.AddDatabaseAccessor(options =>
{
options.AddDbPool();
}, "OpenApi.Database.Migrations");
}
在此处
private readonly ISystemService _systemService;
private readonly IRepository _personRepository;
public SystemAppService(ISystemService systemService, IRepository personRepository)
{
_systemService = systemService;
_personRepository = personRepository;
}

    /// <summary>
    /// 获取系统描述
    /// </summary>
    /// <returns></returns>
    public string GetDescription()
    {
        var persons = _personRepository.AsQueryable(false)
                           .ProjectToType<PersonDto>();

        return _systemService.GetDescription();
    }

发生了异常

数据库信息

  • Sqlite
  • SqlServer
  • Mysql
  • Oracle
  • PGSql
  • Firebird
  • Cosmos

期待结果

期待的结果是?


评论 (1)

Green Cat 创建了任务
Green Cat 关联仓库设置为百小僧/Furion
展开全部操作日志

第一,你看看你的连接字符串是否配置了
第二,你看看你的json文件,右键属性,是否设置为复制了
第三,你的adddbpool没有传入上下文

最后,认真看看文档,samples还有开源示例。

百小僧 任务状态待办的 修改为进行中
百小僧 任务状态进行中 修改为已完成
百小僧 负责人设置为百小僧
百小僧 添加协作者dotNET China
百小僧 添加了
 
疑问
标签
百小僧 添加了
 
重复工单
标签
百小僧 里程碑设置为Furion 2021
百小僧 关联分支设置为master
百小僧 计划截止日期设置为2021-01-15
百小僧 计划开始日期设置为2021-01-14
百小僧 计划截止日期2021-01-15 修改为2021-01-14
百小僧 关联分支master 修改为未关联

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(3)
974299 monksoul 1578937227 8055741 chinadotnet 1606890988
C#
1
https://gitee.com/dotnetchina/Furion.git
git@gitee.com:dotnetchina/Furion.git
dotnetchina
Furion
Furion

搜索帮助