Add migration with different assembly

后端 未结 14 1240
感情败类
感情败类 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(options =>
            options.UseSqlServer(dbConnectionString,
                optionsBuilder =>
                    optionsBuilder.MigrationsAssembly(assemblyName)
            )
       );
    
       ...
    }
    

提交回复
热议问题