The requested page is not available for the requested platform. You are viewing the content for Default platform.

View.ObjectSpace Property

Provides access to the object space within which a View was created.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v19.1.dll

Declaration

public virtual IObjectSpace ObjectSpace { get; }
Public Overridable ReadOnly Property ObjectSpace As IObjectSpace

Property Value

Type Description
IObjectSpace

An IObjectSpace object representing the current View's Object Space.

Remarks

An Object Space (see BaseObjectSpace) represents an instrument that allows managing a cache with persistent objects that are currently used in a View. Via an Object Space, a particular objects set is retrieved from the database to a data set. This allows making changes to objects within this data set, and canceling changes. This does not influence the general database. Use this property to access the current View's Object Space.

Note

Do not use a root View's Object Space for the creation of another root View in it. Instead, create a new Object Space via the XafApplication.CreateObjectSpace method for the new root View.

Note

The ObjectSpace property is not supposed to be used in scenarios where a large amount of data is processed, created or deleted. Instead, use an independent Object Space which is not used by a View. Such an Object Space can be instantiated via the XafApplication.CreateObjectSpace method.

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;
using MainDemo.Module.BusinessObjects;
// ...
public class AssignTasksController : ObjectViewController<ListView, 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<DemoTask> tasks = objectSpace.GetObjects<DemoTask>(taskCriteria);
            foreach(DemoTask task in tasks) {
                task.AssignedTo = person;
            }
        }
    }
}
See Also