Topic: UOW change of the quantitative property

Prompt as is better using unit of work to trace change of the quantitative property (for example goods amount). For example there is a domain essence public class Product {public string Number {get; set;} public string Name {get; set;}.......... public int Quantity {get; set;}//goods amount} How to eliminate the lost update at level transaction business? That is 2 users simultaneously decided to buy the goods, both received value Quantity = 3 after that at first one changed value (3 - 1) = 2, then another as (3 - 1) = 2 turns out that at us was saved 2 instead of 1 What there are candidate solutions of the given task, for example to add property NewQuantity that UoW knew that at first it is necessary to receive delta of new and old value and saved already this change for example by means of DB transaction? I will be glad to any examples and links, in advance thanks.


Re: UOW change of the quantitative property

Variant 1. To use transactions. For example built in a DBMS. Thus the one who updated property the first, it updates, and to the second shows an error, a pier you edited the irrelevant data, it is possible for it to suggest to edit, for example, once again already actual data. It is supposed that transactions opens at show of the form and it kommititsja/is rolled away at form closing. Basically so now do not do. A variant 2. Optimistical locks. About the same, only hands. At form discovery a certain audit of record is remembered, at saving is compared with last and saved only if coincides. To show to the user such dialogue it is the most simple variant. More difficult variant - hands to resolve conflicts, for example in your variant it is possible to understand that if subjects still suffice, it is possible and automatically  this conflict. Or if the different fields which in any way have been not connected with each other were edited, it is possible to make merge of these editings. A variant 3. Event stream. Each single unit of work this separate event. In your case not "to Change 3 on 2", and "to Reduce an amount by unit". Accordingly the difference is not present, in what order these events came, the result will be identical.


Re: UOW change of the quantitative property

Hello, VAD_OS, you wrote: VAD> Prompt as is better using unit of work to trace change of the quantitative property (for example goods amount). It is obvious that for simultaneous change of object from two places, it is necessary to use lock of a changeable resource on modification time and checks of consequences of such change if it is required. The DB does it automatically - simple locks in write time with check , or transactions, insulation and other data integrity. If to do such changes at application level, for example, web applications it is necessary to implement locks/checks by pens. If changes are produced in two different processes of the same machine it is possible to involve for this purpose named . If on different computers it is necessary to invent a bicycle with usage something generally available, files or the same DB. Anyway UoW in all these scenarios absolutely by cash register, since Any means of lock does not possess.


Re: UOW change of the quantitative property

I will specify a question as it to make means of a DB I I understand. Here the question on architecture is faster, we admit yet we do not know that at us the database will be used, it would be desirable to see a code sample (we admit for the shop Internet) which at purchase realization reduces goods amount, in style DDD. If unit of work here does not approach for change tracking probably there is other method. I will underline that for me important to understand, how it can be made using approach DDD. As it is important to understand as it will be  in the code, idea of that that it is possible to trace not itself values and on how many it changed is clear and so, it is interesting as it to implement?