Friday, June 26, 2015
Creating associations between XPO data models in code using the XafTypesInfo API
See my About XAF Types Info Subsystem... blog post before reading.
What's New in this regard?Just wanted to inform you guys that starting with v15.1.4, you can use the solution described in the eXpressApp Framework > Concepts > Business Model Design > Types Info Subsystem > Customize Business Object's Metadata > Create Associations in Code article for that purpose:
The following snippet illustrates how to declare an association between two class' properties when you have no access to these classes code and cannot apply the AssociationAttribute directly.
As you can see in the code above, the IMemberInfo.AddAttribute method's second parameter is true. In this case, Types Info will not reload information from XPDictionary immediatelly. After adding all required attributes, call the XafMamberInfo.Refresh method for each updated member. Alternatively, you can call XafTypesInfo.RefreshInfo for each type containing updated members:
For XAF versions older than 15.1.4 you cannot dynamically establish an association between two persistent classes via the XafTypesInfo API. Instead, you can do this using the XPO's XPDictionary API as shown in the E250: How to customize an XPO business model at runtime example. I hope you will find this small unification helpful.