UNIT OF WORK:
Unit of work keeps track of everything you do during a transaction that can effect the database. It keeps track of everything that needs to be done to alter the database as a result of your work.
There is a system class called UnitOfWork Class in X++ that implements the Unit Of Work Framework. Some of it's details are given below.
Clear
|
Clears all the changes
|
DeleteonSaveChanges
|
Deletes the record on
commit/save changes
|
InsertOnSaveChanges
|
Inserts the record on commit
/save changes
|
UpdateOnSaveChanges
|
Updates the record on commit
/save changes
|
SaveChanges
|
Save the changes on the server
|
Implementing the Unit Of Work:
In this example we will perform bulk insertion on tables , this is where the role of Unit of work comes into play . By means of it we can insert lines against a header record without creating the header first on the basis of the Rec Id that comes as a foreign key in the child table.
Example:
In this example you can see we have created two tables :
- Candidate
- Exam
Where the Exam table behaves as the header table and the Candidate tables acts as the Lines.The Screen shot below shows the relation between them.
After this step we need to set the CreateNavigationPropertyMethods Property to Yes. As Shown in the screen shot below.
After that we need to create a new class and add a Method in it that will perform all the calculations and insertions , as shown in the screen shot below.
Finally we need to call this method in a job. The results can be seen by opening the tables.
In this way the DataSources can be grouped as a unit of work and Ax Client has great support for it.
I believe it was helpful.