Professional Documents
Culture Documents
Discuss the Unit Of Work concept and learn how to enable a group
of tables to be treated as a single transaction.
Discuss events and how events allow you to decouple custom code
from the implementation of the underlying layer.
Introduction
This chapter provides a basic overview of the new technical features in Microsoft
Dynamics AX 2012 and discusses the following new and improved concepts:
Relational Modeling
Date Effectiveness
Unit Of Work
Eventing
4-1
Relational Modeling
As part of data normalization in Microsoft Dynamics AX 2012 multiple new
features, grouped under the Relational modeling concept, are introduced to
improve the following:
Data normalization
o
o
o
Table Inheritance
Just as an X++ class can inherit from another class, in Microsoft Dynamics AX
2012 a table can inherit from another table. As in earlier releases, the Common
table is still the base table for every table. A table that inherits from the base table
is called a derived table.
NOTE: In Microsoft Dynamics AX 2012 the terms parent table and child table
are used to describe foreign key relationships, not inheritance.
In Microsoft Dynamic AX 2012, various new and refactored tables will be using
base and derived tables instead of normal relations to support table inheritance.
The table inheritance improvement is a central framework and is supported in all
framework components. It is model driven and is adapted in the query and X++
language extensions.
This feature enables a developer to build forms that contain base and derived
tables. Forms binding to base tables enable displaying, creating, editing, or
deleting data from all the derived tables.
4-2
Definition
Derived Table
Base Table
Derived
DataSource
Derived Field
Bound Control
Base Field
Bound Control
Polymorphic
Form
Form that contains data from more than one table type
because of a base and derived relation.
Surrogate Key
A surrogate key is a system generated value that acts as the primary key of a
table. This value is typically used instead of a set of fields called the natural key
which would typically act as the primary key of a table. Microsoft Dynamics AX
2012 uses RecId as the surrogate key.
In earlier versions of Microsoft Dynamics AX the client supports lookup controls
where the forms table contains alternate foreign keys. Because the natural
foreign key is contained on the forms table, no additional query joins are needed
to obtain an end-user understandable value. In Microsoft Dynamics AX 2012
new and refactored tables will be using the RecId surrogate key as their primary
key, replacing the keys that contain user understandable values. The form must
be changed to join to the related table to retrieve the user understandable data.
The surrogate key feature enables the client to maintain lookup control behavior
by replacing the surrogate foreign key value with values from the related table.
From a user experience perspective this feature maintains the same functionality
with surrogate foreign key lookups as already exists with natural foreign key
lookups.
4-3
Definition
Reference
DataSource
Reference
DataSource
Field
Surrogate
Key
Replacement
Key
Surrogate
Foreign Key
Replacement
Foreign Key
AutoIdentific
ation Field
Group
Surrogate
key
replacement
fields
Reference
Group
4-4
Date Effectiveness
Date effectiveness is an ability of the application to associate valid from and to
dates with the application artifacts. For example, an agreement can be valid
between a range of dates; similarly interest rates are assigned based on start date
and end date association.
4-5
4-6
4-7
Challenge Yourself!
Use the information that is provided to develop a table to hold positions for an
employee. The positions are for a specific time frame. The system does not
enable time gaps between positions held by an employee.
4-8
4-9
Unit Of Work
Microsoft Dynamics AX 2012 enables the developer to group tables so they are
treated as one single transaction. This concept, called Unit of Work, allows the
developer to have one single trip to the Application Object Server (AOS) to
change multiple records.
Form
In earlier releases of Microsoft Dynamics AX, forms provided limited support for
treating a group of tables as a single transaction. Form behavior involved each
table being individually sent to the AOS to change the database. As part of the
effort to support normalizing tables, the Unit Of Work feature supports saving
multiple tables in a single transaction on a form.
It supports inner and outer joined tables for a single query row to be treated as a
single Unit of Work. Because of the current Form DataSource and Table method
ordering, new methods will be introduced to allow for separation of the clientside logic executed before and after the call to the server.
NOTE: The Unit Of Work feature supports client form ONE-TO-ONE
relationship joins.
Business Logic
Use the Unit Of Work class to manage the:
NOTE: The Unit Of Work feature supports the X++ ONE-TO-ONE relationship
and ONE-TO-MANY relationship joins.
4-10
Disabling a Table
Data Caching
Query Framework
Object ID
Disabling a Table
In Microsoft Dynamics AX 2012, when the configuration key for a table that is
listed in the AOT is disabled, the corresponding table in the underlying database
management system is not dropped. In the earlier version of Microsoft Dynamics
AX when changing the configuration key to disable a table, the table is dropped
from the SQL database, deleting all data in the table. Keeping the data in disabled
tables enables External applications and Microsoft SQL Server cubes to read the
data from the table because they bypass the AOS.
Data Caching
As part of data normalization in Microsoft Dynamics AX 2012 and the
introduction of table inheritance, surrogate key and date effectiveness, data
caching is improved to support the following:
4-11
IS returns a Boolean
Query Framework
Use the new QueryFilter class to filter the result set from an outer join. The
QueryFilter class produces different results than the QueryBuildRange class in
outer joins. The results are different because the QueryFilter class filters later in
the internal query process and helps prevent rows with null values from
appearing in the result set.
BEST PRATICE: Use QueryFilter instead of QueryRange for form queries
because it produces the correct result regardless of join type.
4-12
NOTE: The computed Qty field is given by the ViewMethod called Qty.
Object ID
In earlier releases of Microsoft Dynamics AX, the number of object IDs available
for application elements was limited, both in the range of IDs and by layer. In
Microsoft Dynamics AX 2012, the 16 byte object ID is upgraded to 32 bytes.
This change exponentially increases the number of object IDs.
Eventing
Microsoft Dynamics AX 2012 introduces the concept of events which lets the
user use a publisher and subscriber model when manifesting changes occurring in
the X++ application. Events can be modeled in metadata or be used as a
programming construct and can be handled in either X++ code or in managed
code.
NOTE: Modeled events are only available on classes and not tables or forms.
4-13
Benefits
The main reasons for introducing events are:
Eventing Terminology
Microsoft Dynamics AX 2012 events are modeled after the .NET event concepts
and introduce the following new terminology:
4-14
Term
Definition
Producer
The producer is the logic that contains the code that causes a
change. This means that it is the entity that emits events.
Consumer
Event
Definition
Event
Payload
Delegate
Event Handlers
Event handlers are methods that are called when the delegate is called, either
directly through code (for the coded events) or from the environment (for the
modeled events). The relationship between the delegate and the handlers can be
maintained in code or in the AOT.
The X++ language now features the delegate keyword. When program conditions
meet the programmer's criteria for the event, the X++ code can call the delegate,
and that causes the delegate to call all the event handler methods that are added
to the delegate.
To create a delegate, right-click the class and select New > Delegate.
4-15
Summary
This chapter discussed multiple new features that were introduced as part of the
data normalization in Microsoft Dynamics AX 2012. The features focus on
improvements in developer productivity, end-user experience and total cost of
ownership.
This chapter also discussed the following new and improved concepts:
4-16
Table inheritance.
Date effectiveness.
4-17
2.
3.
4-18
Solutions
Test Your Knowledge
1. Date effectiveness is the ability of the application to associate valid from and
to dates with the application artifacts. Which of the following are valid
statements in regards to data effectiveness? (Select all that apply)
() Developers can create forms that show only current, past or future
records.
() The system automatically resolves date issues if there is gap between
time frames.
() The system automatically resolves date issues if there are overlaps
between time frames.
( ) The system automatically determines the most effective time duration
for a position held by an employee.
2. Which of the following concepts enable a group of tables to be treated as a
single transaction?
() Developers can group multiple table changes into a single trip to the
AOS by using the Unit Of Work class.
( ) Developers can group multiple table changes into a single trip to the
AOS by wrapping the transactions in a TTSbegin and TTSCommit
block.
( ) Developers can group multiple table changes into a single event.
Therefore eventing treats a group of tables as a single transaction.
3. Which of the following are improvements to the data access framework in
Microsoft Dynamics AX 2012? (Select all that apply)
() The TempDB temporary table is hosted in the underlying Microsoft
SQL Server database.
() Disabling the configuration key for a table that is listed in the AOT
does not drop the table in the SQL Database.
( ) Unlike regular SQL Server indexes, full-text indexes must be
manually updated at the same time as data is changed in the
associated tables.
() The X++ language now has the expression operators is and as
4. Which of the following is a true statement in regards to eventing?
() Events can be handled in either X++ code or in managed code.
( ) Events can be handled in X++ code only.
( ) Events can be handled in managed code only.
( ) Events cannot be handled in X++ code or in managed code. Events
are a business concept under the Human Resources (HR) module.
4-19
4-20