Executin a migration for a dbContext that is not in startup project



Hi I just created a new project using ASP.NET Core 1.0 and Entity Framework Core 1.0.This is my project structure:

enter image description here

I wish to avoid adding a referenece to DataAccess layer because all calls must go threw manager layer in order to keep things decoupled and I consider that the WebApi layer should not have any knowledge of what DataAccess technology I am using. If there is any way to not add a reference to Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" please let me know I tryed adding it in the Commercify.DataAccess.Catalog but received an error that stated is not supported class in libraries.

I have created in Commercify.DataAccess.Catalog the following dbContext:

  public class CatalogDbContext: DbContext
    public CatalogDbContext(DbContextOptions<CatalogDbContext> options) 
        : base(options)
    { }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

    public DbSet<CategoryEntity> Categories { get; set; }

Now I want to be able to add a migration to that end I installed: in Commercify.WebApi the following assemblies:

   "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final"
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"

What I want now is to add a migration and in order to do that I executed the following:

dotnet ef migrations add Init

And I got the following error:

No DbContext was found in assembly 'Commercify.WebApi'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.

I remembered that back when dnx was used you could add a -p command and point ef to the project where your dbContext exists so I tryed executing this

dotnet ef migrations add Init -p Commercify.DataAccess.Catalog

And I got the following error:

Unrecognized option '-p'

How can I execute a migration tools for a dbContext that is not in startup project?

7/8/2016 5:36:24 PM

Accepted Answer

AS far as I know, the only way to do this at RTM is to run the migrations from the project that contains the context. This article outlines the process of making it work. Hopefully Microsoft will fix this soon.


7/8/2016 7:29:47 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow