Skip to main content
All docs
V26.1
  • EFCoreObjectSpace.CreateObject(Type) Method

    Creates an object of the specified type.

    Namespace: DevExpress.ExpressApp.EFCore

    Assembly: DevExpress.ExpressApp.EFCore.v26.1.dll

    NuGet Package: DevExpress.ExpressApp.EFCore

    Declaration

    public override object CreateObject(
        Type objectType
    )

    Parameters

    Name Type Description
    objectType Type

    The type of the object to be created.

    Returns

    Type Description
    Object

    A created object of the specified type.

    Remarks

    This method calls the CreateObject(Type) method and throws an exception if the specified type is not registered.

    The following example shows how to use this method:

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Actions;
    using DevExpress.ExpressApp.EFCore;
    using DevExpress.Persistent.Base;
    // ...
    public class AddDepartmentController : ObjectViewController<DetailView, Contact> {
        public AddDepartmentController() {
            ParametrizedAction addDepartmentAction = new ParametrizedAction(
                this, "AddDepartment", PredefinedCategory.Edit, typeof(string));
            addDepartmentAction.Execute += AddDepartmentAction_Execute;
        }
        private void AddDepartmentAction_Execute(object sender, ParametrizedActionExecuteEventArgs e) {
            using (EFCoreObjectSpace objectSpace = (EFCoreObjectSpace)Application.CreateObjectSpace(typeof(Department))) {
                Department department = (Department)objectSpace.CreateObject(typeof(Department));
                department.Title = e.ParameterCurrentValue as string;
                objectSpace.CommitChanges();
            }
            View.Refresh();
        }
    }
    
    See Also