Typically, we define an inheritance hierarchy, assuming there are types, customerbase,customertrialed,customerregistered three types, and the inheritance structure is as follows:
The business object code is defined as follows:
usingDevexpress.xpo; Public classCustomerbase:xpobject {stringFcustomername; Private stringFEMAIL; PublicCustomerbase (Session session):Base(session) {} Public stringCustomerName {Get{returnFcustomername;} Set{setPropertyValue ("CustomerName",reffcustomername, value); } } Public stringEmail {Get{returnFEMAIL;} Set{setPropertyValue ("Email",refFEMAIL, value); } }} Public classCustomerregistered:customerbase {stringfownedproducts; PublicCustomerregistered (Session session):Base(session) {} Public stringownedproducts {Get{returnfownedproducts;} Set{setPropertyValue ("ownedproducts",reffownedproducts, value); } }} Public classCustomertrialed:customerbase {stringftrialedproducts; PublicCustomertrialed (Session session):Base(session) {} Public stringtrialedproducts {Get{returnftrialedproducts;} Set{setPropertyValue ("trialedproducts",refftrialedproducts, value); } }}
We can use the following code to query all customer data.
New Xpcollection<customerbase> (Session1);
This collectionOfTypeIsCustomerbaseSoYouOnlyAccessCustomerbaseTypeOfProperty。NoCanAccessing the properties of a derived class,For example,OwnedproductsPropertyEvenCollection contains customerregistered object this Yes because base class type No know ownedproducts property
To break the limit , use the upcasting feature .
If you want to display the contents of a property, you canmodifies the xpbasecollection.displayableproperties property of the collection . set to this :"OID; CustomerName<customerregistered>ownedproducts ".
Over here,"Oid;CustomerName "IsPropertyValueOfPart <customerregistered>ownedproducts is a property in a derived class
BuildQuery criteriaWhen,AlsoOKUseSameOfGrammar。For example, to all has buy or evaluation xtragrid customer , please using code
New Xpcollection<customerbase>(Session1, Criteriaoperator.parse ("<customerregistered >ownedproducts = ' Xtragrid ' or <customertrialed>trialedproducts = ' Xtragrid ' );
Use the following syntax to query a reference type property .
Public classInvoice:xpobject {customerbase fcustomer; PublicInvoice (Session session):Base(session) {}//This is a reference the Type property. It can reference any customerbase descendant. Publiccustomerbase Customer {Get{returnFcustomer;} Set{setPropertyValue ("Customer",refFcustomer, value); } }}//Uses upcasting to access customerregistered properties.Xpcollection<invoice> invoices =NewXpcollection<invoice>(Session1, Criteriaoperator.parse ("customer.<customerregistered>ownedproducts = ' Xtragrid '"));
As you can see, as long as you are a property in a derived class, you can use < to derive type > to convert, followed by the property name.
The upcasting of the XAF learning notes