Used to indicate to EF Core which properties to update.
Example using the following model.
public class Employee
{
public int Id { get; set; }
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime? BirthDate { get; set; }
}
We only want to update first and last name. Here a valid Employee is passed in
public (bool, Exception exception) UpdateFirstNameAndLastName(Employees employees)
{
try
{
_context.Employees.Attach(employees);
UpdateSpecificField(employees, x => x.FirstName, x => x.LastName);
var affected = _context.SaveChanges();
return (affected == 1, null)!;
}
catch (Exception localException)
{
return (false, localException);
}
}