Táuròs
C# Model with EF Code First
Hello everyone, I need your knowledge to analyze the following problem.
I have a model called Test which is derived from Model Base.
As soon as I perform a PUT action on the WebApi, Created and CreatedBy are also provided with new data. However, these should only be written in the POST method.
The fields are defined in the base model and are as follows
public class BaseModel
{
[Column(Order = 0)]
[DefaultValueSql("NEWID()")]
public Guid Id { get; set; }
[Column(Order = 50)]
[DefaultValueSql("GETDATE()")]
public DateTime Modified { get; set; } = DateTime.Now;
[Column(Order = 51)]
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string ModifiedBy { get; set; } = new HttpContextAccessor().HttpContext.User.Identity.Name;
[Column(Order = 52)]
[DefaultValueSql("GETDATE()")]
public DateTime Created { get; set; } = DateTime.Now;
[Column(Order = 53)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string CreatedBy { get; set; } = new HttpContextAccessor().HttpContext.User.Identity.Name;
}
21 replies