Skip to main content

Clone Object (Copy Data Records)

  • 3 minutes to read

The Clone Object module allows users to clone existing objects in a single click. This functionality can be useful when a user wants to create similar data items without the need to fill all the new data item’s fields.

Clone Object Module Winforms Blazor

Important

XAF does not currently include built-in support for Entity Framework (EF) in this module as its implementation relies on the XPO ORM. Until the Clone Object Module supports EF Core, it is possible to manually integrate any custom or standard Entity Framework solution into your XAF application. For more information on how to do this, refer to the following topic: XAF - Entity Framework Core (EF Core) version of the Clone Object Module.

Add the Clone Object Module to an App

The Clone Object module consists of a single assembly: DevExpress.ExpressApp.CloneObject.Xpo.v23.2.dll (the DevExpress.ExpressApp.CloneObject.Xpo NuGet package).

You can add CloneObjectModule to the common application module to use its CloneObject Action in WinForms, ASP.NET Web Forms, and ASP.NET Core Blazor applications. To do this, add it to the XafApplication.Modules or ModuleBase.RequiredModuleTypes list because a reference to the module assembly is insufficient.

using DevExpress.ExpressApp.CloneObject;
// ...
namespace MySolution.Module {
    public sealed partial class MySolutionModule : ModuleBase {
        public MySolutionModule() {
            // ...
            RequiredModuleTypes.Add(typeof(CloneObjectModule));
        }
    }
}

Tip

  • In .NET 6+ applications, you can call the AddCloningXpo<TBuilder>(IModuleBuilder<TBuilder>, Action<ObjectCloningOptions>) method in your ASP.NET Core Blazor/WinForms application builder.

  • In .NET Framework projects, you can invoke the Module Designer and drag the Clone Object module from the Toolbox to the RequiredModules panel. To add this module to an application project, invoke the Application Designer, drag the CloneObject module from the Toolbox‘s XAF Modules page to the Modules panel on the Designer, and rebuild your solution.
  • You can add modules to your application when you use the Solution Wizard to create a new XAF solution. Select modules in the Choose Additional Modules step.

Activate the Clone Object Module

To activate the CloneObject Action (the Clone… button) for a business object type, set its BOModel | <Class> node’s IsCloneable property to true.

The CloneObject Action is disabled if the current object has unsaved changes because the clone process works in a separate Object Space.

To prevent an individual field or property from being cloned, decorate it with NonCloneableAttribute.

How It Works

The Clone Object module supplies the CloneObjectViewController View Controller. This Controller contains the CloneObject Single Choice Action that targets the selected object for cloning.

The Clone Object module extends the Application Model‘s BOModel | <Class> nodes with the IModelClassCloneable.IsCloneable property. Set it to true to enable the action for objects of the selected type.

Clone Object Module Customization

To implement custom behavior for the CloneObjectViewController or CloneObject Action, create a custom View Controller and access the Controller and its Action in the Controller.Activated event handler.

Handle the CloneObjectViewController.CustomCloneObject event to clone objects with custom logic.

Refer to the CloneObjectViewController.CloneObjectAction topic to see an example. You can handle events exposed by the CloneObjectViewController class.

See Also