Add migration with different assembly

后端 未结 14 1161
感情败类
感情败类 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条回答
  • 2020-12-02 14:49

    Currently I think EF only supports to add migrations on projects not yet on class libraries.

    And just side note for anybody else who wants to add migrations to specific folder inside your project:

    EF CLI not support this yet. I tried --data-dir but it didn't work.

    The only thing works is to use Package Manager Console:

    1. Pick your default project
    2. use -OutputDir command parameter, .e.g., Add-Migration InitConfigurationStore -OutputDir PersistedStores/ConfigurationStore command will output the mgiration to the folder 'PersistedStores/ConfigurationStore' in my project.

    Updates as of 10/12/2017

    public void ConfigureServices(IServiceCollection services)
    {
        ...
    
        string dbConnectionString = services.GetConnectionString("YOUR_PROJECT_CONNECTION");
        string assemblyName = typeof(ProjectDbContext).Namespace;
    
        services.AddDbContext<ProjectDbContext>(options =>
            options.UseSqlServer(dbConnectionString,
                optionsBuilder =>
                    optionsBuilder.MigrationsAssembly(assemblyName)
            )
       );
    
       ...
    }
    
    0 讨论(0)
  • 2020-12-02 14:50

    I had the same problem until I noticed that on the package manager console top bar => "Default Projects" was supposed to be "Project.Data" and not "Project.API".

    Once you target the "Project.Data" from the dropdown list and run the migration you should be fine.

    0 讨论(0)
提交回复
热议问题