I have a situation where two people can work in the same order (stored in the MS SQL database) from two different computers. To prevent data loss in the case when you first need to save your copy of the order, and then a little later the second one will save a copy of it and overwrite the first one, I added a check before the lastSaved (datetime) field before saving.
The code looks something like this:
private bool orderIsChangedByOtherUser(Order localOrderCopy)
{
Order databaseOrder = orderService.GetByOrderId(localOrderCopy.Id);
if (databaseOrder != null &&
databaseOrder.LastSaved > localOrderCopy.LastSaved)
{
return true;
}
else
{
return false;
}
}
This works most of the time, but I found one small error.
orderIsChangedByOtherUser false, , , . lastSaved . , orderIsChangedByOtherUser , true, .
Visual Studio, databaseOrder.LastSaved localOrderCopy.LastSaved , .
datetime SQL:
, SQL Server DATETIME 3,33 (0,00033 ).
, , - , 10 .
: / datetime MS SQL, , ?