do tnet ef миграция add не может быть выполнена: connectionString имеет значение null - PullRequest
0 голосов
/ 14 января 2020

Я пытаюсь создать миграцию в моей программе. Однако, когда я запускаю команду (в командной строке):

dotnet ef migrations add Initial -c idDataContext

, она возвращает нулевую строку подключения, точнее:

System.ArgumentNullException: значение не может быть NULL.
Имя параметра: connectionString

в Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty (строковое значение, String имя-параметра)
в Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UilingBenderSigningSuderSuserSullSq Действие`1 sqlServerOptionsAction)
в MVF2.Startup.b__8_0 (параметры DbContextOptionsBuilder) в C: \ Users \ joao.dias \ source \ repos \ MVF2 \ MVF2 \ Startup.cs: строка 45

Я также пытался запустить консоль диспетчера пакетов, где я пытался выполнить:

add-migration Initial -c idDataContext

Я получаю ту же ошибку, добавляя предупреждение:

Инструменты EF Core версия 2.1.1-rtm-30846 старше, чем во время выполнения 2.1.11-servicing-32099. Обновите инструменты для последних функций и исправлений ошибок

My appsettings.json и addsettings.Development.json:

{
  ...
  "ConnectionStrings": {
    "fmDataContext": "Server=MY-SERVER\\SQLEXPRESS;Database=MYDB;User ID=MYSELF\\myself.me;Integrated Security=SSPI;",
    "idDataContext": "Server=(localdb)\\MSSQLLocalDB;Database=IdentityUsers;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
...
}

(моя программа имеет контексты 2 дБ…)

My Startup.cs:

namespace MVF2
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }
        public AppFeatures features { get; set; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<idDbContext>(options =>
            {
                var connectionString = Configuration.GetConnectionString("idDbContext");
                options.UseSqlServer(connectionString);
            });

            services.AddIdentity<UserModel, IdentityRole>()
                .AddEntityFrameworkStores<idDbContext>()
                .AddDefaultTokenProviders();

            services.AddDbContext<fmDataContext>(options =>
            {
                var connectionString = Configuration.GetConnectionString("fmDataContext");
                options.UseSqlServer(connectionString);
            });

            services.AddTransient<AppFeatures>(x => (features = new AppFeatures
            {
                DevelopmentEnvironment = Configuration.GetValue<bool>("AppFeatures:DevelopmentEnvironment"),
                SqlServerCredentials = Configuration.GetConnectionString("fmDataContext")
            }));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddMemoryCache();

            services.AddSession();
        }

        public void Configure(IApplicationBuilder app, 
                              IHostingEnvironment env, 
                              AppFeatures features)
        {
            app.UseExceptionHandler("/Error.html");

            app.UseAuthentication();

            app.Use(async (context, next) =>
            {
                if (context.Request.Path.Value.Contains("error"))
                    throw new Exception("ERROR!");

                await next();
            });

            app.UseSession();

            app.UseMvc(routes =>
            {
                routes.MapRoute("Default",
                    "{controller=Login}/{action=Login}/{id?}");
            });

            app.UseFileServer();
        }
    }
}

У кого-нибудь есть решение? Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...