Я пытаюсь настроить новую базу данных / миграции с Entity Framework Core с net 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();
});
}
}
Это ошибка:
В файле настроек приложения попробуйте переименовать "connectionString" в "ConnectionStrings".