Microsoft Dynamics Ax 2012:Simple use of Unit of Work

Overview

The main purpose to use UOW is to maintain the referential integrity. At a certain point of time application doesn’t want to be in a situation where violation of referential integrity occurs: for example for the records to be inserted and deleted; sequence should be maintain like Parent record should be inserted first and then the child record, and on deleting the record child should come first prior to parent. When we talk about programmatically maintain this, it is a quite big asks when we are dealing with more normalized data in Dynamics AX 2012.So to cater this “Microsoft Dynamics Ax 2012” provided the “UnitOfWork” programming concept which overcome this and maintain the referential integrity throughout the application.

 

Points of UOW:

  • It is basically a collection of operations(like CRUD) that are performed sequentially and as a Unit
  • “Application code establishes relation between data in memory, modifies data, registers the operation request with the UOW framework,and then request the UOW perform all the registered operation in the database as a unit.”
  • UOW always run on server

Simple Example:

In the below snapshot I have create two tables PurchHeader and PurchLines and a Foreign key relation on the child table PurchLines. You can also see the field for each table

UW1

I have also set the “CreateNavigationPropertyMethods” to Yes.

UW2

CreateNavigationPropertyMethods:

  • This property is only available for foreign key relation
  • When set to YES, it makes the kernel-generated methods on a table buffer to be created.
  • We can  use these methods to set, retrieve and navigate to the related table buffer through the specified relation.

As I mentioned above,UOW can always be used on server,so I have written a class to perform the operation,please also read the comments I have added.

UW3

After that when you open the PurchHeader and PurchLines table you will see the records have been created like

UW4

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s