Proposed Solution:
The PersistentDc should have a MapTo parameter that should be taken into account when generating persistent classes for domain components.
Or at least the XPO's PersistentAttribute should be taken into account.
How do I change database mappings for domain components (DC) and their members?
Answers approved by DevExpress Support
We do not recommend using DC for legacy databases. Thus, we do not provide any means for generating domain components code and logics from existing databases and also have no immediate plans to support this scenario. Please try XPO or Entity Framework data models instead.
We will note this fact in the DC documentation.
Legacy databases is not the only reason you could need this, there could be a convention on how to name table columns that are different of the convetions used to name properties.
Currently, it is possible to solve this task using the DevExpress.Xpo.PersistentAttribute added at runtime. Here is some example code that needs to be added into your ModuleBase descendant (typically located in the Module.xx file):
C#...
private const string GeneratedEntityName = "Test";
public override void Setup(XafApplication application) {
base.Setup(application);
application.TypesInfo.RegisterEntity(GeneratedEntityName, typeof(ITest));
application.TypesInfo.RegisterSharedPart(typeof(ITest));
application.SettingUp += application_SettingUp;
}
private void application_SettingUp(object sender, SetupEventArgs e) {
XPDictionary xpDictionary = XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary;
foreach(XPClassInfo classInfo in xpDictionary.Classes) {
string entityFullName = string.Format("DevExpress.ExpressApp.DC.GeneratedClasses.{0}", GeneratedEntityName);
if(classInfo.FullName == entityFullName) {
classInfo.AddAttribute(new PersistentAttribute("CustomEntityTable"));
}
string sharedPartFullName = string.Format("DevExpress.ExpressApp.DC.GeneratedClasses.{0}_Data", typeof(ITest).Name);
if(classInfo.FullName == sharedPartFullName) {
classInfo.AddAttribute(new PersistentAttribute("CustomSharedPartTable"));
}
}
...
C#
I must note, however, that DC is not supposed to be used for legacy databases where these mappings are usually required. DC does not provide any means for generating domain component code and logic from existing databases either. If you require using DC with an existing database, consider using pure XPO or Entity Framework data models instead.
If you have other use-case scenarios where changing the default database table and column mappings is required, please elaborate more on this in comments.
Thanks for the feedback, Christopher! This solution can certainly be improved, and we will consider this according to our customers' requests.
@Abel: You can use a solution I described above. BTW, would you please elaborate a bit more on your use-case scenario?