Operations¶
New Operation¶
Open the Operations tab at the bottom of the editor. The tab shows one class at a time. Choose the class from the Class list, then click the + button at the bottom of the list of operations.
The + button offers three kinds of operation:
| Item | What it creates |
|---|---|
| New Operation | An empty operation, as described below. |
| New Data Access Operation | A static operation that returns one page of records, with a body of comments that explain how to apply the sorting, filtering and paging that a dataset passes in. |
| New AI Suggested Operation | An operation created with the help of AI. See zAI. |
A data access operation looks like this:
It takes a CommonLib.DataAccessContext[Domain.Product], which carries the sort columns, the filter columns, the page size and the page index, and returns CommonLib.PagedResults[Domain.Product]: the records of the page and the total number of records, so that a list can show its pager.
Defining your Business Logic¶
As soon as you add a new Operation, Studio creates it with the default name NewOperation and a void return type. The list on the left shows the operations of the class, and the code editor on the right shows the selected one.
From this point on, you can define your Business Logic by changing the Operation's definition and adding your required Mamba code into the body of the function
Instance Operations¶
The signature of an Instance Operation has the following syntax:
function return_type OperationName(parameters) {}
/** EXAMPLE **/
function bool CanBeDeleted()
{
bool hasOrders = (Domain.OrderedProduct.GetAll().First(x => x.Order.Status != Domain.Status.Paid) != null);
return !hasOrders;
}
You can use an Object of the Operation's class to call it. An invocation of the CanBeDeleted() instance Operation might look like:
Domain.Product myProduct = Domain.Product.GetByKey(1);
if(myProduct.CanBeDeleted() == false){
DebugLib.Logger.WriteWarnLine("You cannot delete this Product!");
}
Static Operations¶
To define an Operation as static, simple write the static keyword right before the function. Thus, the signature of a Static Operation has the following syntax:
static function return_type OperationName(parameters){}
/** EXAMPLE **/
static function Collection[Domain.Product] GetProductsWithNoPrice()
{
return Domain.Product.GetAll().Where(x => x.Price == 0);
}
You can use the Operation's class to call it. An invocation of the GetProductsWithNoPrice static Operation might look like:
int productsWithNoPrice = Domain.Product.GetProductsWithNoPrice().Length;
if(productsWithNoPrice > 0){
DebugLib.Logger.WriteWarnLine("There are "+productsWithNoPrice+" priceless (no pun intended, lol) Products in your store!");
}
Available Operations¶
If you right-click on an Operation element, a menu like the following will appear :
Non Static¶
You can click on this item to define your Operation as non static, a.k.a. instance Operation
Attention
This operation is available only for static Operations
Static¶
You can click on this item to define your Operation as static
Attention
This operation is available only for instance Operations
Refactor¶
By refactoring an Operation, you are basically changing its name, but in such a way that it is changed in any other Model that might use it.
Find Usages¶
The Find Usages option is very helpful if you want to find all the Models that might be using your Operation. All the hits will be presented in the Console, inside the Symbols panel. From then on, you will be able to Navigate to each Model that uses your Class, by double-clicking on the record you want, presented in said Console.
Move Up¶
Displays the selected Operation one row higher, in the list of the Class' Operations
Move Down¶
Displays the selected Operation one row lower, in the list of the Class' Operations
Cut, Copy, Paste and Clone¶
Cut, Copy and Paste move an operation to another class, or copy it. Clone makes a copy of the selected operation in the same class. Delete removes it.
Design Rules¶
- The name of an Operation inside a Class, must be unique. (Obviously, different Classes may have Operations with the same name) !!! attention Some Operations are pre-defined, for every persisted class (e.g. GetAll(), Find(), GetByKey() etc.). You cannot define Operations with such names, as they are considered reserved. For a list of pre-defined Operations, check here
- Accessor Operations (Getters & Setters) must be Instance Operations. They cannot be
static. - Accessor Operations (Getters & Setters) must have the same datatype as the Attribute they are created for
- A Getter Operation must have zero (0) parameters
- A Setter Operation must have exactly one (1) parameters, with the exact same datatype as its parent Attribute
- An Accessor Operation's name (Getter & Setter) cannot be the same as its parent Attribute's name





