Я использую EF Core в приложении ASP. NET webforms.
Это строка соединения, на которую я ссылаюсь:
<connectionStrings>
<add name="DataContextConnString"
connectionString="Server=.;Database=CMS-Leb;Trusted_Connection=True;" />
</connectionStrings>
DbContext
конфигурация:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["DataContextConnString"].ConnectionString);
}
Когда я обновляю базу данных, она выдает ошибку нулевой ссылки
Ссылка на объект не установлена на экземпляр объекта
стек вызовов:
System.NullReferenceException: Object reference not set to an instance of an object.
at LebaneseLaws.Repositories.DataContext.get__connectionString() in C:\Users\safi.hb\source\repos\saderlex\LebaneseLaws\Repositories\DataContext.cs:line 13
at LebaneseLaws.Repositories.DataContext.OnConfiguring(DbContextOptionsBuilder optionsBuilder) in C:\Users\safi.hb\source\repos\saderlex\LebaneseLaws\Repositories\DataContext.cs:line 27
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[TService](IInfrastructure`1 accessor)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Object reference not set to an instance of an object.