I'm having difficulty getting this to work.
I have a product
table with a version
column that is of type binary fixed length 8, ConcurrencyMode=fixed
, nullable=false
, store generated pattern = computed
.
Now when I update a product
entity in the code I don't see this version
column incremented. I don't see how to make the type of it timestamp
in the database unless I change it in there directly or fiddle about with the metadata for the entity, but then I thought it would be enough to set "store generated pattern". I just want this to work with model first approach setting the properties of the field as mentioned.
My C# code is :
_db = new ProductsContext();
_db.Products.Load();
try
{
using (var db2 = new ProductsContext())
{
db2.Products.Load();
Product p2 = db2.Products.Find(3);
p2.quantity = 2;
db2.SaveChanges();
}
Product p = _db.Products.Find(3);
p.quantity = 3;
_db.SaveChanges();
}
catch (DbUpdateConcurrencyException ex)
{
string a = "";
}
I don't see the exception caught if I run it in debug mode. Thank you.
Ok I found another question with a similar thing being asked and someone on there said to change the database generation template...
Concurrency timestamp column stays null with computed
I assume this is the best way of doing this as the functionality by default doesn't seem to be there. Thankyou for your replies.