Táuròs
Táuròs
CC#
Created by Táuròs on 2/28/2024 in #help
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
CC#
Created by Táuròs on 7/18/2023 in #help
✅ Dataannotations
Hi, is there a way in C# to Build a custom Dataannotation for SQL Columns? With the [Default()] Annotation it is not possible to set the Sql Column to a NEWID() oder GETDATE() Default Value.
17 replies