Skip to main content
.NET 6.0+

IObjectSpace.FindObject(Type, CriteriaOperator) Method

Searches for the first object that matches the specified criteria and is of the specified type. The search takes uncommitted changes into account.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v23.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

object FindObject(
    Type objectType,
    CriteriaOperator criteria
)

Parameters

Name Type Description
objectType Type

A Type object which is the type of objects to search for.

criteria CriteriaOperator

A CriteriaOperator descendant which is the criteria to match persistent objects.

Returns

Type Description
Object

An object which is the first persistent object which matches the specified criteria. null (Nothing in Visual Basic) if there is no persistent object which matches the criteria.

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;
        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 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, you don’t have to implement the FindObject method. The BaseObjectSpace class’ FindObject(Type objectType, CriteriaOperator criteria) method invokes a public virtual FindObject(Type objectType, CriteriaOperator criteria, Boolean inTransaction) method passing true as the inTransaction parameter. So, to implement an object search, override the public virtual BaseObjectSpace.FindObject method.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FindObject(Type, CriteriaOperator) method.

Note

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