Showing Method Results
Summary
A Read method can return an entity — including a [Virtual] one. Point a DataGraph at the returned entity's Guid and it fetches and renders it; the graph builds the OData request for you.
graph LR
M["[Method] returns an entity"] --> G["Guid of the result"]
G --> D["DataGraph(Builder, EntityGuid)"]
D --> R["graph issues OData GET<br/>($select/$expand from the builder)<br/>then renders"]
Write a GraphBuilder for the returned type and bind a DataGraph to the Guid — no manual request code.
Virtual entity from a method
The method returns a virtual entity built in business logic:
// model
[Method("Create down payment", MethodType.Read)]
public partial DownPaymentWorkflow CreateDownPayment();
// logic
salesOrder.Method(s => s.CreateDownPayment).Do((order, args) =>
new DownPaymentWorkflow(args.Context) { Order = order });
A virtual entity isn't persisted, so run the call inside a workflow to keep it in memory while the graph loads and edits it:
@code {
Guid? _resultGuid;
async Task OpenAsync()
{
await _workflowOData.BeginWorkflowAsync();
var res = await _workflowOData.GetAsync($"SalesOrder({_orderGuid})/CreateDownPayment", "$select=Guid");
if (res.IsSuccess(out var ok, out _))
_resultGuid = ok.Result?["Guid"]?.GetValue<Guid>();
}
}
@if (_resultGuid is not null)
{
<DataGraph Builder="DownPaymentWorkflowGraph.Build" DataSet="@_dataSet" EntityGuid="@_resultGuid">
<PropertyGroup Path="Workflow" Columns="2" ShowTitle="true" />
<MethodButton Method="Pay" Label="Pay now" />
</DataGraph>
}
Build _dataSet from the same workflow-scoped client so its loads and PATCHes stay in the workflow. The builder names the properties to load:
public static GraphBuilder Build() => new GraphBuilder("DownPaymentWorkflow")
.Property("SelectedPaymentOption")
.Property("PercentOfTotal")
.Group("Workflow", g => g
.Property("SelectedPaymentOption")
.Property("PercentOfTotal"));
Editing a virtual property PATCHes through the workflow; computed values and validation update each round-trip, just like a persisted entity. Commit the workflow to persist any real effects.
Persisted entity from a method
When the method returns a saved entity, no workflow is needed — invoke it the same way (POST for a Modify method), then bind the returned Guid directly:
<DataGraph Builder="SummaryGraph.Build" DataSet="@_summaryDataSet"
EntityGuid="@_summaryGuid" DisplayMode="DisplayMode.View">
<PropertyGroup Path="Summary" Columns="2" ShowTitle="true" />
</DataGraph>
A dotted path in the builder (e.g. .Property("Document.DocNumber")) makes the graph add $expand=Document($select=DocNumber) — navigation works on method-returned entities too.
Returning a collection
A method can also return IQueryable<T>; the result stays queryable, so OData options ($filter, $select, $expand) apply. See Methods for query-method examples.
How the request is handled
- The server wraps an entity result as a queryable (
SingleResult), so the graph's$select/$expandapply; collection results stay queryable for$filter/$top/$skip. Virtual properties are selectable and expandable like any other. DataGraphturns theGraphBuilderinto that OData query and loads theEntityGuid— you don't write the request.- If a method returns the same entity it was called on, skip all this: a
MethodButtonwith aDataSetauto-merges the result back into the open graph.
See also
- Virtual Entities and virtual entities in workflows
- Method Buttons — invoking methods from the UI
- Graph Definitions — the
GraphBuilderAPI - Methods