Skip to main content
.NET Framework 4.6.2+

DataSourcePropertyAttribute Class

Applied to business classesreference and collection properties. Specifies the name of a collection property used as the data source for a List View displayed in a Lookup Property Editor or invoked by the LinkUnlinkController.LinkAction Action in a popup window.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

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

Remarks

You can filter the data source for the List View displayed in a Lookup Property Editor or in the LinkUnlinkController.LinkAction Action’s popup window. For this purpose, apply the DataSourceProperty attribute to the target property. Specify a collection property using the attribute’s DataSourcePropertyAttribute.DataSourceProperty parameter. This collection must contain objects of the target property’s type or its descendants. These objects will actually be displayed in the Lookup List View of the target property. The collection property must provide information on the element type. It can be an associated collection, a generic collection or an untyped collection decorated with the CollectionAttribute.

The following example demonstrates how to use the DataSourceProperty attribute:

using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
// ...
[DefaultClassOptions]
public class Order : BaseObject {
    private Accessory fAccessory;

    // Specify the AvailableAccessories collection as a data source for the Accessory property
    [DataSourceProperty(nameof(AvailableAccessories))]
    public virtual Accessory Accessory {
        get { return fAccessory; }
        set { SetPropertyValue(ref fAccessory, value); }
    }

    private IList<Accessory> fAvailableAccessories;

    [NotMapped, Browsable(false)] // Prohibits showing the AvailableAccessories collection separately
    public IList<Accessory> AvailableAccessories {
        get {
            if (fAvailableAccessories == null) {
                // Retrieve all Accessory objects
                fAvailableAccessories = ObjectSpace.GetObjects<Accessory>();
            }
            return fAvailableAccessories;
        }
    }
}

public class Accessory : BaseObject {
    public virtual string Name { get; set; }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

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

Note

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. So, the Server, ServerView, InstantFeedback, or InstantFeedbackView mode option and the DataSourceProperty attribute do not work simultaneously.

You can set the collection that will be displayed by the Lookup List View when the source property is not specified. To do this, pass a DataSourcePropertyIsNullMode enumeration value as the DataSourceProperty attribute’s DataSourcePropertyAttribute.DataSourcePropertyIsNullMode parameter. If you pass the DataSourcePropertyIsNullMode.CustomCriteria value, specify criteria for filtering the target property’s data source. To do this, pass the criteria using the DataSourcePropertyAttribute.DataSourcePropertyIsNullCriteria parameter. In the criteria, you can use Function Criteria Operators and the Current Object Parameter.

The values that you pass as the DataSourceProperty attribute’s parameters are assigned to the corresponding properties of the Application Model‘s BOModel | <Class> | OwnMembers | <Member> node. Note, you can set or change values of these attributes directly in the Application Model using the Model Editor. The values that are set in the Application Model are used when constructing the application UI.

Note

  • By default, the criteria which is set for a property using the DataSourceProperty attribute in a base business class remains applied in the business class descendants.
  • An object which is added to a lookup via the New Action is always displayed, regardless of whether or not the DataSourceProperty or DataSourceCriteria attributes are applied.

Inheritance

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