Skip to main content
All docs
V24.1
.NET 6.0+

DataSourcePropertyAttribute.UsedProperties Property

Gets names of properties that affect lookup list construction for the current data source property.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.ExpressApp.v24.1.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public string[] UsedProperties { get; }

Property Value

Type Description
String[]

An array of System.String values that specify property names.

Remarks

A lookup list for a property may depend on values of other properties. If that’s the case, specify these properties in the UsedProperties parameter of the DataSourcePropertyAttribute. This setting allows XAF to automatically refresh Lookup Property Editors in Blazor applications when values of related properties change. Otherwise, you would need to refresh lookup editors manually.

Example

This code example demonstrates a data model in which a customer’s order can be assigned a Product, an Accessory, and a Boolean IncludeGlobalAccessories value. The Lookup Property Editor for the Accessory property is populated with data from the AvailableAccessories property. That property returns a filtered list based on the Product property value (if a product is specified) and the IncludeGlobalAccessories value.

Since the AvailableAccessories property uses other properties in calculations, the Accessory lookup editor must be updated when a user changes these properties. To achieve this, add the names of the used properties to the UsedProperties collection parameter in the DataSourcePropertyAttribute declaration.

using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;

public class Order : BaseObject {
    public virtual int OrderId { get; set; }
    public virtual Product Product { get; set; }
    // Specify that AvailableAccessories must be used as a data source property,
    // and the Product and IncludeGlobalAccessories properties are used in calculations.
    [DataSourceProperty(nameof(AvailableAccessories), nameof(Product), nameof(IncludeGlobalAccessories))]
    public virtual Accessory Accessory { get; set; }

    [NotMapped, Browsable(false)] // Prohibits showing the AvailableAccessories collection separately 
    public virtual IList<Accessory> AvailableAccessories {
        get {
            IQueryable<Accessory> available;
            if (Product == null) {
                // Show only Global Accessories when the Product is not specified 
                available = ObjectSpace.GetObjectsQuery<Accessory>().Where(t => t.IsGlobal == true);
            }
            else {
                // Leave only the current Product's Accessories in the availableAccessories collection 
                if (IncludeGlobalAccessories == false) {
                    available = ObjectSpace.GetObjectsQuery<Accessory>().Where(t => t.Product == Product);
                }
                else {
                    available = ObjectSpace.GetObjectsQuery<Accessory>().Where(t => t.Product == Product || t.IsGlobal == true);
                }
            }
            return available.ToList();
        }
    }
    public virtual bool IncludeGlobalAccessories { get; set; }
}

The image below illustrates the result:

Result

See Also