Skip to main content
.NET 6.0+

IObjectSpace.GetObjectsCount(Type, CriteriaOperator) Method

Returns the number of objects specified.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v23.2.dll

NuGet Package: DevExpress.ExpressApp


int GetObjectsCount(
    Type objectType,
    CriteriaOperator criteria


Name Type Description
objectType Type

A Type object that identifies the type of objects against which the calculation will be performed.

criteria CriteriaOperator

The CriteriaOperator that specifies the criteria for object selection in the database.


Type Description

An integer value that is the count of persistent objects that satisfy the specified criteria.


This method is intended to calculate the number of persistent objects in the database. For instance, this method is used before retrieving objects for the Lookup Property Editor. If there are more than the specified value, the Find editor is available.

The following code limits the number of objects that are created with the New Action:

using DevExpress.ExpressApp;
using DevExpress.Persistent.BaseImpl;
using DevExpress.ExpressApp.SystemModule;
public class LimitTaskAmountController : ViewController {
    private NewObjectViewController controller;
    protected override void OnActivated() {
        controller = Frame.GetController<NewObjectViewController>();
        if (controller != null) {
            controller.ObjectCreating += controller_ObjectCreating;
    void controller_ObjectCreating(object sender, ObjectCreatingEventArgs e) {
        if ((e.ObjectType == typeof(Task)) && 
            (e.ObjectSpace.GetObjectsCount(typeof(Task), null) >= 3)) {
                e.Cancel = true;
                throw new UserFriendlyException(
                    "Cannot create a task. Maximum allowed task count is exceeded.");
    protected override void OnDeactivated() {
        if (controller != null) {
            controller.ObjectCreating -= controller_ObjectCreating;

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetObjectsCount(Type, CriteriaOperator) method.


The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also