The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

IObjectSpace.FindObject<ObjectType>(CriteriaOperator) Method

Searches for the first object that matches the specified criteria. The object's type is designated by the specified generic type parameter. The search takes uncommitted changes into account.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v19.2.dll

Declaration

ObjectType FindObject<ObjectType>(
    CriteriaOperator criteria
)
Function FindObject(Of ObjectType)(
    criteria As CriteriaOperator
) As ObjectType
ObjectType FindObject<ObjectType>(
    CriteriaOperator criteria
)
Function FindObject(Of ObjectType)(
    criteria As CriteriaOperator
) As ObjectType
ObjectType FindObject<ObjectType>(
    CriteriaOperator criteria
)
Function FindObject(Of ObjectType)(
    criteria As CriteriaOperator
) As ObjectType

Parameters

Name Type Description
criteria CriteriaOperator

A CriteriaOperator descendant which is the criteria for matching persistent objects.

Parameters

Name Type Description
criteria CriteriaOperator

A CriteriaOperator descendant which is the criteria for matching persistent objects.

Parameters

Name Type Description
criteria CriteriaOperator

A CriteriaOperator descendant which is the criteria for matching persistent objects.

Returns

Type Description
ObjectType

An object which is the first persistent object which matches the specified criteria.

Returns

Type Description
ObjectType

An object which is the first persistent object which matches the specified criteria.

Returns

Type Description
ObjectType

An object which is the first persistent object which matches the specified criteria.

Type Parameters

Name Description
ObjectType

Type Parameters

Name Description
ObjectType

Type Parameters

Name Description
ObjectType

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 = objectSpace.FindObject<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<ObjectType> method. The BaseObjectSpace class' FintObject<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.

See Also