I have a table in my sql server database called "Orders" to which i need to give concurrent access(optimistic concurrency).
To achieve that i have a timestamp column called rversion.
Here is a sample of the code for the action to delete an order :
public ActionResult CancelOrder(int? ohid,string rowversion)
{
/*Validation tests.....**/
try
{
byte[] rvbytes = Convert.FromBase64String(rowversion);
dbRepo.deleteSalesOrderHeaderById((int)ohid, rvbytes);
dbRepo.Save();
return RedirectToAction("MyOrders", "Commande");
}
catch(DbUpdateConcurrencyException concurrencyex)
{
return View("Error", (object)"Concurrency error, the order that you tried to delete was updated or deleted by another user, please retry again");
}
catch (Exception ex)
{
return View("Error", (object)"Uknown error , please retry");
}
}
I have two questions:
Is it practical to pass the rowversion as a parameter in the URL? as i need that to populate the cancel order links in the orders view.
Second, as we see the Timestamp field of the database was converted by entity framework as byte[] ,how to convert it to string to pass to the url , and reconvert it back to the database as timestamp?
As we can see in the code i tried to convert from string to byte[] like this, but i have to be sure it's the right thing
byte[] rvbytes = Convert.FromBase64String(rowversion)
Thank you.