Целевой проект не соответствует сборке миграций - PullRequest
0 голосов
/ 11 июня 2018

У меня есть мультипроектное решение, где я не могу успешно добавить миграцию базы данных из основного проекта University.Application.Контекст Db определен в сборке University.Infrastructure.

При попытке dotnet ef migrations add Initial в каталоге проекта University.Application я получаю следующую ошибку:

Your target project 'University.Application' doesn't match your migrations assembly 'University.Infrastructure'. Either change your target project or change your migrations assembly. Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("University.Application")). By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.

В основном проекте в Startup.cs я определил сборку миграций:

services.AddEntityFrameworkSqlServer()
                .AddDbContext<UniversityContext>(options => 
                {
                    options.UseSqlServer(configuration["ConnectionString"],
                    sqlServerOptionsAction: sqlOptions => 
                    {
                        sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
                        ...

И в моем проекте University.Infrastructure я определил UniversityDbContextDesignFactory (я использую две разные строки подключения длявремя выполнения и дизайн):

public class UniversityContextDesignFactory : IDesignTimeDbContextFactory<UniversityContext>
    {
        public UniversityContext CreateDbContext(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder<UniversityContext>()
                .UseSqlServer("Server=localhost,1433;Database=UniversityDb;User Id=sa;Password=Pass@word;");

            return new UniversityContext(optionsBuilder.Options, new NoMediator());
        }
        ...

Что мне здесь не хватает?Я попытался следовать официальной документации без удачи.Любая помощь будет высоко ценится.

...