Implement Dependent Reference Properties slave reference attributes implement (XPO)

In this lesson, you will learn how to implement properties whose values can depend on other properties. The Manager property will be added to the Contact class. By default, it will be represented by a lookup editor containing all Contacts that exist in the database. However, you may need this editor to contain Contacts from the same Department. In addition, you may need the Position of these Contacts to be "Manager". To do this, use the DataSourcePropertyAttribute and DataSourceCriteriaAttribute attributes for the Manager property.

In this lesson, you will learn how to achieve it may depend on the property value of other properties. "Manager" attribute is added to the "Contact" category. By default, it will be represented by a lookup editor contains all contacts that exist in the database. However, you may want to contact the editor included from the same sector. In addition, you may need to position these contacts is "manager." To do this, use the Manager attribute DataSourceProperty properties and data source standards Properties.

Note Note

Before proceeding, take a moment to review the following lessons.

  • Inherit from the Business Class Library Class (XPO)
  • Implement Custom Business Classes and Reference Properties (XPO)
  • Set a One-to-Many Relationship (XPO)

Before proceeding, please take a moment to review the following courses.

  • (XPO) inherited from the business class library class
  • Traffic class and implement custom reference attributes (XPO)
  • Set-many relationship (XPO)

 

  • Add a new Manager property of the Contact type to the Contact class. Apply the DataSourceProperty attribute to this property, as shown below.

The "contact" type of new "manager" attribute to "Contact" category. This property is applied to the DataSourceProperty properties, as shown below.

[DefaultClassOptions]
public class Contact : Person {
    //...
    private Contact manager;
    [DataSourceProperty("Department.Contacts")]   
    public Contact Manager {
       get { return manager; }
       set { SetPropertyValue(nameof(Manager), ref manager, value); }
    }
    //...
}

 

  • With the DataSourceProperty attribute applied, the Manager lookup editor will contain Contact objects that are specified by the Department object's Contacts property.
  • After applying DataSourceProperty property, Manager editor will look for include the "Department" object "Contacts" Contact object attributes specified.

 

  • Run the application and select Contact in the drop-down list of the New combo box. The Contact Detail View will be invoked. Specify the Department property and expand the Manager lookup editor. Make sure that the Department property of the listed objects is the same as those you specified above.

  • Run the application, and select "Contacts" in the drop-down list of "new combinations" box. Calls the "Contact Details" view. Specifies the "Department" property and expand the "Manager to find" editor. Ensure that the objects listed in the "Department" attribute you specified above objects are the same.

    Tutorial_BMD_Lesson7_1

  • Apply the DataSourceCriteria attribute to the Contact class' Manager property as shown below.

  • The "Standard Data Source" attribute is applied to human contact manager properties as follows.
public class Contact : Person {
    //...
    [DataSourceProperty("Department.Contacts")]
    [DataSourceCriteria("Position.Title = 'Manager' AND Oid != '@This.Oid'")]
    public Contact Manager {
        // ...
    }
    // ...
}

 

  • With the DataSourceCriteria attribute applied, the Manager lookup editor will contain Contact objects that satisfy the criteria specified in the attribute parameter.
  • After applying DataSourceCriteria property, Manager editor will look like "Contact" to meet the target attribute parameters specified conditions.

 

  • Run the application. Set the Position property to "Manager" for several Contact objects.

  • Run the application. The "position" attribute set to a plurality of "contact" object "manager."

    Managers_XAF

  • Select Contact in the New (new_dropdown_btn) button's drop-down list. The Contact Detail View will be invoked. Specify the Department property and expand the Manager lookup editor. Check to make sure that the Position property is set to "Manager" for each of the listed objects.

  • In the "New (new_dropdown_btn)" select "Contacts" button's drop-down list. Calls the "Contact Details" view. Specifies the "Department" property and expand the "Manager to find" editor. Check to make sure that each object listed in the "position" attribute set to "manager."

    Tutorial_BMD_Lesson7_2

  • If the Department property is not specified for a Contact, you can provide another data source for the Manager lookup editor. To do this, specify the second parameter for the DataSourceProperty attribute. In the code below, this parameter is set to the DataSourcePropertyIsNullMode.SelectAll value. You can also set the DataSourcePropertyIsNullMode.SelectNothing or DataSourcePropertyIsNullMode.CustomCriteria values. In the latter case, a third parameter is required to specify a criterion.

如果未为联系人指定"部门"属性,则可以为 Manager 查找编辑器提供其他数据源。为此,请为 DataSourceProperty 属性指定第二个参数。在下面的代码中,此参数设置为 DataSourcePropertyIsNullMode。您还可以设置"数据源属性"NullMode。在后一种情况下,需要第三个参数来指定条件。

[DefaultClassOptions]
public class Contact : Person {
    //...
    [DataSourceProperty("Department.Contacts",DataSourcePropertyIsNullMode.SelectAll)]
    [DataSourceCriteria("Position.Title = 'Manager' AND Oid != '@This.Oid'")]
    public Contact Manager {
        // ...
    }
    // ...
}

 

  • The code above will show all contacts in the Manager lookup editor, if the Department property is not specified.
  • Run the application and check the results.
  • 如果未指定"部门"属性,则上述代码将显示"管理器查找"编辑器中的所有联系人。
  • 运行应用程序并检查结果。
Note

You can implement the same behavior at design time. For details, refer to the Filter Lookup Editor Data Source lesson.

注意
您可以在设计时实现相同的行为。有关详细信息,请参阅筛选器查找编辑器数据源课程。

 

You can see the code demonstrated here in the MySolution.Module | Business Objects | Contact.cs (Contact.vb) file of the Main Demo installed with XAF. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

You can MySolution module |. Business Objects |. Main demo installation and XAF Contact.cs (Contact.vb) file installed in the main demo application % the PUBLIC% \ Documents \ DevExpress the Demos 19.2 \ Components \ eXpressApp Framework \ MainDemo by default . the Available Online at The ASP.NET Version IS AT http://demos.devexpress.com/XAF/MainDemo/

.

 

Guess you like

Origin www.cnblogs.com/foreachlife/p/Implement-Dependent-Reference-Properties.html