DataSourceCriteriaAttribute Class
Specifies the criteria expression used to filter source data for a reference, collection, or enumeration property.
Namespace: DevExpress.Persistent.Base
Assembly: DevExpress.ExpressApp.v25.1.dll
NuGet Package: DevExpress.ExpressApp
#Declaration
#Remarks
You can apply a DataSourceCriteriaAttribute
to a reference, collection, or enumeration property of a business class.
- For reference and collection properties, the attribute specifies the criteria expression that filters the lookup list view or a list view invoked by the LinkUnlinkController.LinkAction action.
- For enumeration properties, the attribute specifies the criteria expression that filters values displayed in the combo box.
Use DataSourceCriteriaAttribute.DataSourceCriteria to specify filter criteria. You can use function criteria operators and the current object parameter. Refer to the following help topic for more information about building criteria: Ways to Build Criteria.
using DevExpress.Data.Filtering;
//...
EnumProcessingHelper.RegisterEnum<OrderStatus>();
using DevExpress.Persistent.BaseImpl.EF;
using System.ComponentModel.DataAnnotations;
// ...
[DefaultClassOptions]
public class Order : BaseObject {
[DataSourceCriteria("IsGlobal = true")]
public virtual Accessory Accessory { get; set; }
//For enum property
[DataSourceCriteria("Status = ##Enum#MyNamespace.OrderStatus,Pending# or Status = ##Enum#MyNamespace.OrderStatus,Confirmed# or Status = ##Enum#MyNamespace.OrderStatus,Processing#")]
public virtual OrderStatus Status { get; set; }
}
public class Accessory : BaseObject {
public virtual bool IsGlobal { get; set; }
}
public enum OrderStatus {
Pending,
Confirmed,
Processing,
Shipped,
Delivered,
Canceled,
Returned
}
// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
#Application Model
DataSourceCriteria property value is assigned to the IModelCommonMemberViewItem.DataSourceCriteria property of the Application Model. You can specify property value directly in the Model Editor at the following path: BOModel | <Class> | OwnMembers | <Member>.
#Important Notes
- The criteria specified by the
DataSourceCriteria
attribute in a base business class remains applied in descendants. DataSourceProperty
andDataSourceCriteria
attributes do not affect visibility of objects added to a lookup via the New action.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 isTask.Project.Manager
, then\@This
refers toTask
and not toProject
.- DataSourceCriteriaPropertyAttribute overrides
DataSourceCriteriaAttribute
when both attributes are applied to the same property. - When applying
DataSourceCriteriaAttribute
to an enumeration property, the left part of the criteria string must match the property name.