The upcasting of the XAF learning notes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.