entity-framework-core-2.2

ConfigurationManager return null when using to extract database connection string when add migration

风格不统一 提交于 2021-01-22 04:19:12
问题 I am using Entity Framework Core in my .NET Core console app. I store my connection string in the App.config file and use ConfigurationManager in context class to access the connection string. When I want to add new migration to my project I get the following error: System.NullReferenceException: Object reference not set to an instance of an object. at EF_tut.Context.OnConfiguring(DbContextOptionsBuilder optionsBuilder) in C:\..\Context.cs:line 12 at Microsoft.EntityFrameworkCore.DbContext

Ignore duplicate entries and commit successful ones on DbContext.SaveChanges() in EF Core

放肆的年华 提交于 2020-05-27 04:25:07
问题 I have an ASP .Net Core 2.2 Web API. In one of my controller actions, I am adding a bunch of rows to a MySQL database table (I'm using Pomelo). So for example: _dbContext.AddRange(entities); _dbContext.SaveChanges(); The entities I'm adding have two primary keys (composite primary key) and the keys are already populated in the entities collection when I add them to DbContext (i.e. I am setting the keys myself - there is no "auto increment" or anything like that where the database generates

Ignore duplicate entries and commit successful ones on DbContext.SaveChanges() in EF Core

扶醉桌前 提交于 2020-05-27 04:24:25
问题 I have an ASP .Net Core 2.2 Web API. In one of my controller actions, I am adding a bunch of rows to a MySQL database table (I'm using Pomelo). So for example: _dbContext.AddRange(entities); _dbContext.SaveChanges(); The entities I'm adding have two primary keys (composite primary key) and the keys are already populated in the entities collection when I add them to DbContext (i.e. I am setting the keys myself - there is no "auto increment" or anything like that where the database generates

Ignore duplicate entries and commit successful ones on DbContext.SaveChanges() in EF Core

丶灬走出姿态 提交于 2020-05-27 04:23:17
问题 I have an ASP .Net Core 2.2 Web API. In one of my controller actions, I am adding a bunch of rows to a MySQL database table (I'm using Pomelo). So for example: _dbContext.AddRange(entities); _dbContext.SaveChanges(); The entities I'm adding have two primary keys (composite primary key) and the keys are already populated in the entities collection when I add them to DbContext (i.e. I am setting the keys myself - there is no "auto increment" or anything like that where the database generates