Skip to main content
.NET Framework 4.5.2+

DataSourceCriteriaAttribute Class

Applied to business classesreference and collection properties. Specifies the criteria expression used to filter the 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.1.dll

NuGet Package: DevExpress.ExpressApp

Declaration

[AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
public sealed class DataSourceCriteriaAttribute :
    ModelExportedValueAttribute

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 DataSourceCriteria attribute to the target property. Specify a criteria for filtering via the attribute’s dataSourceCriteria parameter. This value will be assigned to the IModelCommonMemberViewItem.DataSourceCriteria property of the Application Model‘s BOModel | <Class> | OwnMembers | <Member> node. Note, you can set or change this property’s value directly in the Application Model via the Model Editor.

The following example demonstrates how to use the DataSourceCriteria attribute:

using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;
using System.ComponentModel.DataAnnotations;
// ...
[DefaultClassOptions]
public class Order : BaseObject {
    [DataSourceCriteria("IsGlobal = true")]
    public virtual Accessory Accessory { get; set; }
}

public class Accessory : BaseObject {
    public virtual bool IsGlobal { get; set; }
}

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

To learn how to write criteria correctly, refer to the Ways to Build Criteria topic. In criteria, you can use Function Criteria Operators and the Current Object Parameter.

Note

  • By default, the criteria which is assigned to a property via the DataSourceCriteria 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.

  • In DataSourceCriteria, \@This refers to the master object (for which the lookup editor is displayed) even if the lookup editor displays a complex property. For example, if the property is Task.Project.Manager, then \@This refers to Task and not to Project.

  • DataSourceCriteriaPropertyAttribute overrides DataSourceCriteriaAttribute when both attributes are applied to the same property.

For details on this and other techniques of Lookup Property Editor data source filtering, refer to the How to: Implement Cascading Filtering for Lookup List Views.

Inheritance

Object
Attribute
DevExpress.Persistent.Base.ModelExportedValueAttribute
DataSourceCriteriaAttribute
See Also