Skip to main content
All docs
V24.2
.NET 8.0+
  • The page you are viewing does not exist in the .NET Framework 4.6.2+ platform documentation. This link will take you to the parent topic of the current section.

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

EFCoreObjectSpace.CreateObject(Type) Method

Creates an object of the specified type.

Namespace: DevExpress.ExpressApp.EFCore

Assembly: DevExpress.ExpressApp.EFCore.v24.2.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