We are trying to BulkUpdate(EFCore.BulkExtensions) a table based on primary key. We need to update ONLY Name based on Id and not Age
Model
public class Student
{
public int Id { get; set; } // Primary Key
public string Name { get; set; }
public int Age { get; set; }
}
Here is the code I used to try to update a student's name using primary key Id
List<Student> students = new List<Student>();
students.Add(new Student()
{
Id = 1,
Name = "Name 1",
Age = 25
});
var updateByProperties = new List<string> { nameof(Student.Id) };
var propToExclude = new List<string> { nameof(Student.Id) };
var bulkConfig = new BulkConfig { UpdateByProperties = updateByProperties, PropertiesToExclude = propToExclude };
_dbContext().BulkUpdate(students, bulkConfig);
My expectation here is it will update column Name of a row which has Id as 1 but I am getting the following error
The given key 'Id' was not present in the dictionary.
So how do I BulkUpdate(EFCore.BulkExtensions) a table based on primary key.