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

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

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

#Remarks

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

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 and DataSourceCriteria 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 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.
  • When applying DataSourceCriteriaAttribute to an enumeration property, the left part of the criteria string must match the property name.

#Inheritance

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