Darfer

Darfer

  • NA
  • 17
  • 2.3k

DateTime column not automaticaly updated

Sep 27 2016 2:33 AM
I work on an Entity Framework 6.1.3, ASP.NET MVC 5, Code First with an existing databse project. My database (SQL Server 2016) includes a table with a “ModifiedDate” (datetime, DEFAULT (getdate)) column. When trying to create a new record in browser the server applies the value automatically as it should be done.
Unfortunately, when I update an existing record the old ModifiedDate value as it is shown in the textbox is applied (not the current date). Moreover, the ModifiedDate textbox should always be inactive to the user, both when creating or editing a record (i.e. the user shouldn’t be allowed to enter a value himself).
 
This is the model class for the “Title” table:
  1. public partial class Title  
  2. {  
  3. public int TitleID { getset; }  
  4.   
  5. [Column("Title")]  
  6. [Required]  
  7. [StringLength(50)]  
  8. public string Title1 { getset; }  
  9.   
  10. [DatabaseGenerated(DatabaseGeneratedOption.Computed)]  
  11. public DateTime? ModifiedDate { getset; }  
  12. }  
Any suggestions would be appreciated.
 
Darfer

Answers (16)