eShopOnContainers – No parameterless constructor defined for type dbcontext

Hi everyone,

Another eShopOnContainers post. Today I was setting up migrations and ran into the following error:

Found DbContext ‘CatalogContext’.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type ‘CatalogContext’. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
—> System.MissingMethodException: No parameterless constructor defined for type ‘Catalog.Api.Infrastructure.CatalogContext’.
at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)

This turned out to be because I was missing the following from my CatalogContext:

public class CatalogContextDesignFactory : IDesignTimeDbContextFactory
{
public CatalogContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder()
.UseSqlServer(“Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;Integrated Security=true”);

return new CatalogContext(optionsBuilder.Options);
}
}


by

Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

%d bloggers like this: