Mari
Mari

Reputation: 69

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:

'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.' 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.

Upvotes: 0

Views: 248

Answers (1)

Ismail Diari
Ismail Diari

Reputation: 519

You have all except a DBContext class, you should provide a DbContext with the needed DbSets and with the correct configuration if needed.
Please note also that you potentially will need an EntityConfiguration for each of your POCOs.
Or Else, if you have already dbcontext, then it is not well configured.

Upvotes: 0

Related Questions