I have a scenario where my template has the fields CreatedOn and UpdatedOn and following what I found in the EF Core documentation I implemented my class as follows
builder.Entity<Registro>(b =>
{
b.Property<DateTime>("CreatedOn")
.IsRequired()
.ValueGeneratedOnAdd()
.HasDefaultValueSql("GETUTCDATE()");
b.Property<DateTime>("UpdatedOn")
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasDefaultValueSql("GETUTCDATE()"); ;
});
public class Registro
{
public Guid Id { get; set; }
public string Nome { get; set; }
}
In insert both fields are filled with the correct value, however in the update does not happen as expected that would update the field with a new date. It also follows how I am doing the entity update
public void Put(Guid id, [FromBody]string value)
{
var r = context.Registros.SingleOrDefault(x => x.Id == id);
r.Nome = value;
context.SaveChanges();
}