Skip to main content
.NET 8.0+

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DataSourcePropertyAttribute Class

Specifies the data source for a reference, collection, or enumeration property.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.ExpressApp.v25.1.dll

NuGet Package: DevExpress.ExpressApp

#Declaration

[AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
public class DataSourcePropertyAttribute :
    ModelExportedValuesAttribute

#Remarks

You can apply a DataSourcePropertyAttribute to a reference, collection, or enumeration property of a business class.

  • For reference and collection properties, the attribute specifies the data source for the lookup list view and the list view invoked by the LinkUnlinkController.LinkAction action.
  • For enumeration properties, the attribute specifies the data source with enumeration values. These values are displayed in the combo box.

Use DataSourcePropertyAttribute.DataSourceProperty to specify the name of a collection property used as the data source. The collection must contain objects of the target property’s type or its descendants. The collection property must provide information about the element type. It can be an associated collection, a generic collection, or an untyped collection decorated with the CollectionAttribute.

using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
// ...
[DefaultClassOptions]
public class Order : BaseObject {
    private Accessory fAccessory;
    // Set the AvailableAccessories collection as a data source for the Accessory property
    [DataSourceProperty(nameof(AvailableAccessories))]
    public Accessory Accessory {
        get { return fAccessory; }
        set {
            SetPropertyValue(nameof(Accessory), ref fAccessory, value);
        }
    }
    private XPCollection<Accessory> fAvailableAccessories;
    [Browsable(false)] // Prohibits showing the AvailableAccessories collection separately
    public XPCollection<Accessory> AvailableAccessories {
        get {
            if(fAvailableAccessories == null) {
                // Retrieve all Accessory objects
                fAvailableAccessories = new XPCollection<Accessory>(Session);
            }
            return fAvailableAccessories;
        }
    }

    //For Enumeration Properties
    private OrderStatus fStatus;
    [DataSourceProperty(nameof(PendingConfirmedAndProcessing))]
    public OrderStatus Status {
        get { return fStatus; }
        set {
            SetPropertyValue(nameof(Status), ref fStatus, value);
        }
    }
    [NotMapped, Browsable(false)] // Prohibits showing the AvailableAccessories collection separately
    private IList<OrderStatus> PendingConfirmedAndProcessing
        => new List<OrderStatus>() { OrderStatus.Pending, OrderStatus.Confirmed, OrderStatus.Processing };
}

public class Accessory : BaseObject {
    // ...
    private string fName;
    public string Name {
        get { return fName; }
        set {
            SetPropertyValue(nameof(Name), ref fName, value);
        }
    }
}
public enum OrderStatus {
    Pending,
    Confirmed,
    Processing,
    Shipped,
    Delivered,
    Canceled,
    Returned
}

For more information, refer to the following help topic: How to: Implement Cascading Filtering for Lookup List Views.

#Default Collection

Use the DataSourcePropertyIsNullMode property to specify the default collection displayed by the lookup list view if DataSourceProperty returns null.

If you set the DataSourcePropertyIsNullMode property to CustomCriteria, use the DataSourcePropertyIsNullCriteria property to specify the filter criteria. In the criteria, you can use function criteria operators and the current object parameter.

Note

  • The criteria specified by the DataSourceProperty attribute in a base business class remains applied in descendants.
  • DataSourceProperty and DataSourceCriteria attributes do not affect visibility of objects added to a lookup via the New action.

#Application Model

DataSourcePropertyAttribute property value is assigned to the corresponding property of the Application Model. You can specify the property value directly in the Model Editor at the following path: BOModel | <Class> | OwnMembers | <Member>.

#Limitation

The Server, ServerView, InstantFeedback, or InstantFeedbackView mode option and the DataSourceProperty attribute do not work simultaneously.

An independent server-mode collection is created as a data source for a lookup ListView when the IModelListView.DataAccessMode option is set to Server, ServerView, InstantFeedback, or InstantFeedbackView for that ListView model. However, when the DataSourcePropertyAttribute is applied for the lookup property, the property pointed in the attribute is used as a lookup data source, and the standalone independent server-mode collection is not created and is not used at all. The reason is that the data source property getter contains logic calculated on the client side and the data source is populated by the client application at the moment when the lookup editor requests to display objects.

#Inheritance

Object
Attribute
DevExpress.Persistent.Base.ModelExportedValuesAttribute
DataSourcePropertyAttribute
See Also