Skip to main content
.NET 8.0+

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 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

IObjectSpace.GetObjects<T>(CriteriaOperator, Boolean) Method

Returns an IList collection of objects via the current Object Space.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

#Declaration

IList<T> GetObjects<T>(
    CriteriaOperator criteria,
    bool inTransaction
)

#Parameters

Name Type Description
criteria CriteriaOperator

A CriteriaOperator which specifies the criteria for object selection.

inTransaction Boolean

true, if the filter takes unsaved changes into account; otherwise, false. Has effect in XPO only.

#Type Parameters

Name Description
T

The Type of objects that are retrieved.

#Returns

Type Description
IList<T>

A IList collection that contains the persistent objects of the specified type. Only objects that satisfy the specified criteria will be retrieved to this collection.

#Remarks

The following example uses a Parametrized Action to search for a Person by LastName, and then assigns all deferred tasks to that person.

using System.Collections.Generic;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.Base.General;
using DevExpress.Persistent.BaseImpl;
// ...
public class AssignTasksController : ObjectViewController<ListView, MainDemo.Module.BusinessObjects.DemoTask> {
    public AssignTasksController() {
        ParametrizedAction assignTasksAction = new ParametrizedAction(
            this, "AssignTasks", PredefinedCategory.Edit, typeof(string));
        assignTasksAction.Execute += AssignTasksAction_Execute;
    }
    private void AssignTasksAction_Execute(object sender, ParametrizedActionExecuteEventArgs e) {
        IObjectSpace objectSpace = View.ObjectSpace;
        string personParamValue = e.ParameterCurrentValue as string;
        CriteriaOperator personCriteria = CriteriaOperator.Parse("Contains([LastName], ?)", personParamValue);
        Person person = (Person)objectSpace.FindObject(typeof(Person), personCriteria);
        if(person != null) {
            CriteriaOperator taskCriteria = CriteriaOperator.Parse("[Status] = ?", TaskStatus.Deferred);
            IList<MainDemo.Module.BusinessObjects.DemoTask> tasks =
                objectSpace.GetObjects<MainDemo.Module.BusinessObjects.DemoTask>(taskCriteria, false);
            foreach(MainDemo.Module.BusinessObjects.DemoTask task in tasks) {
                task.AssignedTo = person;
            }
        }
    }
}

When implementing the IObjectSpace interface in the BaseObjectSpace class’s descendant, don’t implement the GetObjects<T> method. It’s implemented in the BaseObjectSpace class. To get the specified objects, the BaseObjectSpace.GetObjects<T>(CriteriaOperator criteria, bool inTransaction) method invokes a generic protected virtual CreateCollection method that does nothing and returns null. So, you should override the generic CreateCollection method in your descendant.

See Also