CopyEntity


CopyEntity

Table of Contents

CopyEntity is a method, that is available within any entity. In the model of the AI-Framework, the call is: .Copy. This is the functional name. It copies all fields of an entity (which is a record in memory) to a new entity.

Read more about this in How to > Basic concepts > Entities 

 

Example of usage

public IMethodCall MakeCopyOfOrder()
{
    return Method(() =>
    {
        var currentOrder = OrdersView.CreateItemReference();
        var newOrder = OrdersView.CreateItemReference();

        return new Body
        {
            currentOrder.Assign(OrdersView.Current),
            newOrder.Assign(currentOrder.Copy()),
            newOrder.AssignNextOrderNr(),
            newOrder.OrderDateTime.Assign(DateTimeExpression.Now),
            newOrder.Status.Assign(OrderStatus.Open),
            Orders.Save()
        };
    })
    .SetWorkDescription("make a copy of an order")
    .SetImage(CommonImages.ArrowRight)
    .Call();
}

 

Explanation of the example

This is a method, named MakeCopyOfOrder(), which is situated inside the Entity OrderEntity. It has therefore direct access to the data, related to the table Order.

 

How to use this

Anywhere in the model code, where the OrderEntity is available, a button can be placed on a form, that invokes this method: Orders.MakeCopyOfOrder(). If, for example, the form shows a list of orders, clicking the button will make a copy of the order that is currently selected in that list.

 



Article ID: 359
Created: Tue, Jan 28, 2020
Last Updated: Tue, Jan 28, 2020

Online URL: https://wiki-ai-framework.abstract-it.nl/article/copyentity-359.html