I have a SQL table with a datetime field of Version_Date as a primary key, I can see its data saved as this format: "2018-09-26 00:00:00 000",
Now, from the razor view with a update when I change this field from razor view and save it, here is the code in controller:
[HttpPost]
[ValidateAntiForgeryToken]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Version_Date,xxxx")] tbl_Version_Information tbl_Version)
{
if (ModelState.IsValid)
{
// Date(tbl_Version.Version_Date) = xxx //I need to do some changes here_
db.Entry(tbl_Version).State = EntityState.Modified;
db.SaveChanges();
}}
Now, when I changed the Version_Date field from razor view and save it, I got this error:
System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: 'Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded
After some searches, I found the error caused by the Version_Date field since it is a Primary key in SQL table with millisecond portion of data, how
to make this update working?
Member
366 Points
2214 Posts
How to make this DateTime as primary key issue work when saving in mvc?
Mar 04, 2020 01:48 PM|Peter Cong|LINK
I have a SQL table with a datetime field of Version_Date as a primary key, I can see its data saved as this format: "2018-09-26 00:00:00 000",
Now, from the razor view with a update when I change this field from razor view and save it, here is the code in controller:
[HttpPost]
[ValidateAntiForgeryToken]
Now, when I changed the Version_Date field from razor view and save it, I got this error:
System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: 'Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded
After some searches, I found the error caused by the Version_Date field since it is a Primary key in SQL table with millisecond portion of data, how to make this update working?
Thanks a lot,