Methods
Methods define custom actions on entities beyond standard CRUD operations. They are exposed as OData actions on the entity's API endpoint.
[Method]
Declares a custom action on an entity.
[Method("Display label", MethodType)]
public partial ReturnType MethodName(ParameterType parameters);
Methods must be partial — the source generator creates the API action and the implementation is provided by business logic.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
label |
string |
Yes | Display label for the action |
type |
MethodType |
Yes | Whether the method reads or modifies data |
Description |
string? |
No | User-facing description |
Technical |
string? |
No | Developer notes |
MethodType
| Value | Description | Return Type |
|---|---|---|
MethodType.Read |
Reads data without side effects | Must have a return type |
MethodType.Modify |
Changes entity state | Typically void |
Modify Methods
Use MethodType.Modify for actions that change data:
//TODO: Remove parameter classes in examples
[ApiEntity]
public partial class SalesOrder : EntityBase
{
[Method("Update order status", MethodType.Modify)]
public partial void UpdateStatus(StatusParams statusParams);
[Method("Copy order from another order", MethodType.Modify)]
public partial void ReorderFrom(ReorderParams sourceOrder);
[Method("Create details from accessory products", MethodType.Modify)]
public partial void CreateDetails(AccessoryParameter parameter);
}
Read Methods
Use MethodType.Read for data retrieval actions. These must return a value:
[ApiEntity]
public partial class Customer : EntityBase
{
[Method("Get destination contacts", MethodType.Read)]
public partial IQueryable<Contact> GetDestinationContacts();
}
Parameter Classes
Method parameters are plain C# classes with public properties. No special attributes are needed.
public class StatusParams
{
public SalesOrderStatus NewStatus { get; set; }
}
public class ReorderParams
{
public Guid SalesOrderGuid { get; set; }
}
public class AccessoryParameter
{
public Guid ProductGuid { get; set; }
public decimal Quantity { get; set; }
public Guid[] SelectedAccessories { get; set; } = [];
}
For simple actions that need no parameters, omit the parameter entirely:
[Method("Recalculate totals", MethodType.Modify)]
public partial void RecalculateTotals();
Nested Parameter Classes
Parameter classes can contain complex types:
public class GenerateProductionsParams
{
public bool OverrideBreedTemplate { get; set; }
public List<BreedProductionTemplate> Templates { get; set; } = [];
}
Where Is the Implementation?
The entity model only declares the method signature. The actual implementation lives in a [Logic] class in the appropriate business logic project. See the Events documentation for how to implement method handlers.
Complete Example
namespace Benevia.ERP.Model.Hatchery;
[ApiEntity]
public partial class Flock : EntityBase
{
[Required]
[Property<DataTypes.IdText>("ID")]
public partial string ID { get; set; }
[Method("Generate Flock Productions", MethodType.Modify)]
public partial void GenerateFlockProductions(GenerateProductionsParams parameters);
[Method("Save Breed Production Template", MethodType.Modify)]
public partial void SaveBreedProductionDatas(SaveProductionsParams parameters);
}
// Parameter classes — plain C# POCOs
public class GenerateProductionsParams
{
public bool OverrideBreedTemplate { get; set; }
public List<BreedProductionTemplate> Templates { get; set; } = [];
}
public class SaveProductionsParams
{
public List<FlockProductionTemplateData> ProductionDatas { get; set; } = [];
}