I would like to know how to safely update data when programming with Entity Framework 4(ODAC).
void DescreaseInventory(int id, int qty){
var order = (from o in context.Orders where o.ID ==id select o).FirstOrDefault;
if( order != null ){
if( ((Order)order).Qty < qty )
throw new ApplicationException( "Not Enough Inventory!!" );
else
((Order)order).Qty -= qty;
}
else{
//...some code...
}
//will content.savechange
}
This code will be dangerous(evade the qty checking) once race condition happens. Who knows how to do this correctly?
EDIT: Now I know EF4 provide a mechanism to make a column as a tracking token. But I'm not sure how can I create this kind of column in oracle DB(9i)? what's the proper column type?