Я пытаюсь настроить новую базу данных / миграцию с Entity Framework Core с сетевым ядром 3, но вот следующая ошибка. с надстройкой начальная миграция
Можете ли вы помочь мне, пожалуйста?
Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
appsettings.json
{
"connectionString": {
"MyConnection": "data source=Localhost;Database=MyDataBase;User Id=MyUser;Password=MyPass;MultipleActiveResultSets=True"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
private void ConfigureJson(MvcNewtonsoftJsonOptions obj)
{
obj.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
obj.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
string contactConnection = Configuration.GetConnectionString("MyConnection");
services.AddDbContext<ApplicationContactDbContext>(options =>
options.UseSqlServer(contactConnection)
);
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddNewtonsoftJson(ConfigureJson);
services.AddCors(options =>
{
options.AddPolicy("EnableCORS", builder => { builder.WithOrigins("*").AllowAnyHeader().AllowAnyMethod(); });
});
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = "http://localhost:5000",
ValidAudience = "http://localhost:5000",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKeyYoSoyExitoso@345"))
};
});
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
Это ошибка:
System.ArgumentNullException: значение не может быть нулевым.
Имя параметра: connectionString
в Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty (строковое значение, строковое имя_параметра)
в Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer (DbContextOptionsBuilder optionsBuilder, String connectionString, Action 1 sqlServerOptionsAction)
at Elapoint.ContactExtension.MicroService.Startup.<>c__DisplayClass5_0.<ConfigureServices>b__0(DbContextOptionsBuilder options) in E:\PersonalesX\Proyectos\PV5\NetCore\Extensions\Contacts\Api\Startup.cs:line 37
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c__DisplayClass1_0
2.b__0 (IServiceProvider p, DbContextOptionsBuilder b)
в Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory [TContext] (IServiceProvider applicationServiceProvider, действие 2 optionsAction)
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c__DisplayClass10_0
1.b__0 (IServiceProvider p)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory (FactoryCallSite factoryCallSite, контекст RuntimeResolverContext)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor 2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor
2.VisitCallSite (ServiceCallSite callSite, аргумент TArgument)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve (ServiceCallSite callSite, область действия ServiceProviderEngineScope)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine. <> c__DisplayClass1_0.b__0 (область действия ServiceProviderEngineScope)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (Тип serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService (Тип serviceType)
в Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService (поставщик IServiceProvider, Тип serviceType)
в Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService [T] (поставщик IServiceProvider)
в Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions. <> c__10 1.<AddCoreServices>b__10_1(IServiceProvider p)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor
2.VisitCallSiteMain (ServiceCallSite callSite, аргумент TArgument)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (CallSite ServiceCallSite, контекст RuntimeResolverContext, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache (ServiceCallSite singletonCallSite, контекст RuntimeResolverContext)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor 2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor
2.VisitCallSiteMain (ServiceCallSite callSite, аргумент TArgument)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (CallSite ServiceCallSite, контекст RuntimeResolverContext, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache (ServiceCallSite singletonCallSite, контекст RuntimeResolverContext)
в Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor 2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetServices[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextTypes()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextType(String name)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0
1.b__0 ()
в Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute (Действие действия)
Значение не может быть нулевым.
Имя параметра: connectionString