Add migration with different assembly

后端 未结 14 1245
感情败类
感情败类 2020-12-02 14:25

I am working on a project with ASP.NET CORE 1.0.0 and I am using EntityFrameworkCore. I have separate assemblies and my project structure looks like this:

Pr         


        
14条回答
  •  猫巷女王i
    2020-12-02 14:32

    All you have to do, is modify your ConfigureServices like this:

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext(item => item.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection"), 
                b => b.MigrationsAssembly("Project.Api")));
    
            services.AddIdentity()
                    .AddEntityFrameworkStores()
                    .AddDefaultTokenProviders();
        }
    

    By Default VS will use the Assembly of the project where the DbContext is stored. The above change, just tells VS to use the assembly of your API project.

    You will still need to set your API project as the default startup project, by right clicking it in the solution explorer and selecting Set as Startup Project

提交回复
热议问题