IObjectSpace.GetObjects(Type, CriteriaOperator) Method
Returns an IList collection of objects of the specified type, retrieved to the current Object Space and filtered according to the specified criteria.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.2.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Parameters
Name | Type | Description |
---|---|---|
type | Type | The type of objects that are retrieved. |
criteria | CriteriaOperator | A CriteriaOperator which specifies the criteria for object selection. |
Returns
Type | Description |
---|---|
IList | 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;
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;
Person person = objectSpace.FirstOrDefault<Person>(p => p.LastName.Contains(personParamValue));
if(person != null) {
CriteriaOperator taskCriteria = CriteriaOperator.Parse("[Status] = ?", TaskStatus.Deferred);
IList tasks = objectSpace.GetObjects(
typeof(MainDemo.Module.BusinessObjects.DemoTask), taskCriteria);
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 method. It’s implemented in the BaseObjectSpace class. To get the specified objects, the BaseObjectSpace.GetObjects(Type type, CriteriaOperator criteria) method invokes a protected virtual CreateCollection method that does nothing and returns null. So, you should override the CreateCollection method in your descendant.