DataSourceCriteriaAttribute Class
Applied to business classes‘ reference 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
#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 Data
Source attribute in a base business class remains applied in the business class descendants.Criteria An object which is added to a lookup via the New Action is always displayed, regardless of whether or not the Data
Source or DataProperty Source attributes are applied.Criteria In
Data
,Source Criteria \@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 isTask.
, thenProject. Manager \@This
refers toTask
and not toProject
.- Data
Source overrides DataCriteria Property Attribute Source when both attributes are applied to the same property.Criteria Attribute
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.