Error executing add-Migration . Entity Framework Core

Asked

Viewed 187 times

0

I am using version 2.2.4 of Ef core and version 3.0.5 preview of . net core sdk

The mistake is : Unable to create an object of type 'AppDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 When I try to generate a database migration script.

startup.Cs

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using APICatalogo.Context;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace APICatalogo
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            services.AddDbContext<AppDbContext>
                (options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));
            services.AddControllers()

My db context class:

using APICatalogo.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace APICatalogo.Context
{
    public class AppDbContext : DbContext
    {

        public AppDbContext(DbContextOptions<AppDbContext> options)
        : base(options)
        {
        }
        public DbSet<Categoria> Categorias { get; set; }
        public DbSet<Produto> Produtos { get; set; }

    }
}
  • Already tried to upgrade your application to the stable sdk version?

  • I found this link with a suggestion that makes sense. The solution proposed for this problem was to add an implementation of the interface "Idesigntimedebcontextfactory".

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.