简体   繁体   English

尚未为此 DbContext 配置数据库提供程序

[英]No database provider has been configured for this DbContext

I'm using two context, but now the need to create a RepositoryBase has arisen, but returns this error to me:我正在使用两个上下文,但现在需要创建一个 RepositoryBase,但返回此错误给我:

'No database provider has been configured for this DbContext. '没有为此 DbContext 配置数据库提供程序。 A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider.可以通过覆盖 DbContext.OnConfiguring 方法或在应用程序服务提供者上使用 AddDbContext 来配置提供者。 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.'如果使用 AddDbContext,则还要确保您的 DbContext 类型在其构造函数中接受 DbContextOptions 对象并将其传递给 DbContext 的基本构造函数。 this.dbSet = context.Set() this.dbSet = context.Set()

RepositoryBase存储库库

 public class RepositoryBase<TEntity> : IDisposable where TEntity : class
{

    internal ApplicationDbContext2 context;
    internal DbSet<TEntity> dbSet;
    public RepositoryBase(ApplicationDbContext2 context) 
    {
        this.context = context;
        this.dbSet = context.Set<TEntity>();
    }

UnitOfWork工作单位

public class UnitOfWork : DbContext, IDisposable
{
    private ApplicationDbContext2 context = new ApplicationDbContext2();
    private RepositoryBase<Album> albumRepository;

I put the beginning for you to see, how can I fix ??我把开头给你看,我该怎么修?? I tried to add dbContext, but i couldn't run.我尝试添加 dbContext,但无法运行。

You have all except a DBContext class, you should provide a DbContext with the needed DbSets and with the correct configuration if needed.除了 DBContext 类之外,您拥有所有其他类,您应该提供具有所需 DbSet 和正确配置的 DbContext(如果需要)。
Please note also that you potentially will need an EntityConfiguration for each of your POCOs.另请注意,您可能需要为每个 POCO 设置一个 EntityConfiguration。
Or Else, if you have already dbcontext, then it is not well configured.否则,如果您已经有了 dbcontext,那么它就没有配置好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InvalidOperationException:没有为此DbContext配置数据库提供程序 - InvalidOperationException: No database provider has been configured for this DbContext Azure KeyVault for DBContext:“尚未为此DbContext配置数据库提供程序” - Azure KeyVault for DBContext: “No database provider has been configured for this DbContext” InvalidOperationException:没有为此DbContext配置数据库提供程序。 可以通过覆盖DbContext来配置提供程序 - InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext 没有为此 DbContext 配置数据库提供程序。 可以通过覆盖 DbContext.OnConfiguring 来配置提供程序 - No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring ASP.NET API:尚未为此DbContext配置任何数据库提供程序 - ASP.NET API: No database provider has been configured for this DbContext add-Migration 错误 没有为此 DbContext 配置数据库提供程序 - add-Migration Error No database provider has been configured for this DbContext 添加迁移错误:尚未为此DbContext配置数据库提供程序 - Add migration error: No database provider has been configured for this DbContext LINQPad EF Core 没有为此 DbContext 配置数据库提供程序 - LINQPad EF Core no database provider has been configured for this DbContext InvalidOperationException:没有为此 DbContext 配置具有存储库模式的数据库提供程序 - InvalidOperationException: No database provider has been configured for this DbContext with Repository pattern 无法解决此错误,“尚未为此 DbContext 配置数据库提供程序” - Cannot solve this error, "No database provider has been configured for this DbContext"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM