简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM