See Also:
Add dynamic field to a DC entity
How to modify table structure for DC?
How to customize a domain component interface (DC) type information at runtime, e.g. define a custom member
Answers approved by DevExpress Support
Hello,
I want to close the current request with two possible solutions discussed earlier:
1. Creating custom members (except for associations) in code within the XafApplication.SettingUp event handler as follows:
C#using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Win;
using DevExpress.ExpressApp.Xpo;
namespace XCRM.Win {
public partial class XCRMWinApplication : WinApplication {
public XCRMWinApplication() {
InitializeComponent();
this.SettingUp += XCRMWinApplication_SettingUp;
}
void XCRMWinApplication_SettingUp(object sender, SetupEventArgs e) {
string customMemberName = "CustomMemberForDomainComponent";
Type customMemberType = typeof(string);
string customMemberExpression = "";//Dennis: Leave it empty if it is non-calcualted/persistent field.
TypeInfo domainComponentTypeInfo = (TypeInfo)XafTypesInfo.Instance.FindTypeInfo(typeof(XCRM.Module.ICRMContact));
IMemberInfo memberInfo = domainComponentTypeInfo.FindMember(customMemberName);
if(memberInfo == null) {
memberInfo = domainComponentTypeInfo.CreateMember(customMemberName, customMemberType, customMemberExpression);
}
}
2. Declaring custom members via the Model Editor using the feature described in eXpressApp Framework > Concepts > Business Model Design > Types Info Subsystem > Customize Business Object's Metadata. Using this feature, you can indirectly define custom IModelMember objects in the Application Model so that they are later used to customize the types metadata when the static DevExpress.ExpressApp.ApplicationModelManager.AddCustomMembersFromModelToTypeInfo method (this particular API is internal and may be changed in the future) is called internally or from custom code.
IMPORTANT NOTES
- Runtime associations between domain components are not currently supported. Defining reference properties whose type is another domain component will work in simple cases only when no shared parts are involved due to the runtime DC entities generation specifics.
- Do not mix the Domain Components (DC) technology with Non-Persistent Objects. This functionality is unsupported for POCO marked with the DomainComponentAttribute. If you attempt to call the ITypeInfo.CreateMember method for such a POCO, you will receive a meaningful exception. Refer to the How to create custom/dynamic properties for a non-persistent POCO marked with DomainComponentAttribute article for possible solutions.
@Peter: As far as I remember it is not currently possible to define collection properties via the ITypesInfo API for both DC and pure XPO. In the E250 example, it is done using the XPDictionary directly. I have not yet tested this approach with DC to say for sure whether it is supported as well, but I will do that and inform you of my results.
@Peter: I have verified that adding a XPCollection<IPersistentObject2> type property is neither supposed to work for DC nor for pure DC.
Please open a separate ticket in the Support Center and describe your business scenario from the end-user perspective in detail, so we can find a good technical solution for you.
@Dennis: I opened a ticket for this: https://www.devexpress.com/Support/Center/Question/Details/T208712
See http://community.devexpress.com/blogs/eaf/archive/2013/02/05/domain-components-calculated-properties-application-model.aspx
Hi Dennis, with the XAF webinar held this last week, it was mentioned that you were working on and trying to add OOB functionality for adding dynamic members either via code or the model editor (hopefully for version 13.2 but I know that there are no promises :). As part of that implementation are you working on including DC support for this feature? Please say yes :). If not could you please consider this as well.
Thanks,
Steve
Hello Steven,
I am afraid I cannot say much about support for dynamic members in DC, because it is too premature and also because the solution we are currently researching is not metadata based. In any event, thank you once again for checking this scenario with us. I appreciate it.
Hello Guys,
It is technically possible to add custom members for DC after the registered entities were generated. For instance, this can currently be done on the XafApplication.SetupComplete event. However, this event is a bit late for such customization, because the application model is already initialized. So, we are going to provide an event for you that will be raised before the application model is initialized, but after registered entities were generated. I hope this helps.
Hi Dennis, can you please comment on whether this new event will be in 13.2? Could you also please provide a short code snippet on how to accomplish this when it is released?
@Steven: Thanks for your interest. Once we have news on this, we will surely provide additional details and code snippets.
@Steven: I forgot to mention that currently you can already handle the XafApplication.SettingUp event as shown in DC - Provide the capability to change database mappings for domain components and their members.