[DevExpress Support Team: CLONED FROM K18270: Can I override properties of business objects?]
guys, this stuff with new keywork would be great that there is not one small problem with Column Chooser. After several "new" steps in every class I have property Status that behaves as expected but when you have to add some new field from Column Chooser there you find columns with same name. Users are little bit confused. How to remove this extra properties?
How to remove base class properties from the Column Chooser when overriding them in descendants
Answers approved by DevExpress Support
Hello Goran,
This tree is built based on the business model, and all visible properties from the business model are added in it. So, the only way to remove properties from this tree is to make them invisible through the [Browsable(false)] attribute. If this solution does not meet your needs, please describe your scenario in greater detail. Note that overriding properties in descendants is unusual for XPO, and there is likely a better solution for your scenario.
I did not quite understand why overriding properties is required in this example. It seems that you can implement the Invoice.Partner, PurchaseInvoice.Supplier and SalesInvoice.Customer properties independently of each other, without the "new" keyword. It is unclear how the "new" keyword can be helpful in this scenario. Please note that if you, for example, create a Partner property with the "new" keyword in the PurchaseInvoice class, your database will have two independent columns - Invoice.Partner and PurchaseInvoice.Partner. The PurchaseInvoice.Partner property will not get its values from Invoice.Partner - the Invoice.Partner property will just be hidden from the UI. In this case, it seems more correct to remove the Partner property from the Invoice class, and add independent Supplier and Customer properties to the PurchaseInvoice and SalesInvoice classes.
Hi Anatol,
let me elaborate. I'm using new keyword to create correct type of Invoice.Partner in descendant classes. For example, original property in Document is
public Party Partner
{
get { return partner; }
set { SetPropertyValue("Partner", ref partner, value); }
}
and in descendant class FinancialDocument it becomes
[ModelDefault("Caption", "Bill To Customer")]
public new LegalOrganisation Partner
{
get { return base.Partner; }
set { base.Partner = value; }
}
This works great combined with [MapInheritance(MapInheritanceType.ParentTable)] - it allows me to keep inheritance chain, associations, automatic filtering by type; there is correct type when the property is accessed from code etc. Everything seems fine with this approach but Column Chooser. Good solution for Column Chooser would be to keep property from most-descendant class ie. while building the list it should check if property with the same name is already added to the tree.
Unfortunately, [Browsable(false)] is not helpful because I want to show list of all documents to my users, and hiding Partner (even if the context of that information might not be known to user) is a no-no.
Note: I've changed type of property in descendant class. Otherwise I would need to cast in code and write filters - things that c# and Xaf are currently doing for me.
So, any chance of changing Column Chooser or perhaps a hint how to override its behaviour?
Thank you for the detailed description. This design looks reasonable. However, I have tested it and could not reproduce the initial issue you described - the Object Model tree contained nodes with the Partner and Bill To Customer names. So, it appears that you can change the overridden properties' captions to distinguish between them in the Object Model dialog. Please let me know if your application's behavior is different.