Vidyano tip: Return a query from a custom action

Basic solution

Custom actions are described in the Vidyano documentation on this page. The method you have to implement looks like this:

public static PersistentObject MyAction(AdventureWorksEntityModelContainer context, CustomActionArgs e)

You can easily see that this action has to return a Persistent Object (PO). But what if you want the result of the action to display a query? Returning a query clearly doesn’t work. There is however a simple solution to this problem.

Vidyano allows a developer to create “Virtual persistent objects”. If we create a PO without any attributes, but with one query, the result will be that the Vidyano client will display the query directly. Let’s create a virtual PO with the name “MyQueryPO” and look at the code of the action:

public static PersistentObject MyAction(AdventureWorksEntityModelContainer context, CustomActionArgs e)
    return Manager.Current.GetPersistentObject("MyQueryPO”);

Let’s see what this does:

  1. The custom action still returns a PO.
  2. The client will receive the PO and render it. Since there are no attributes the PO will be rendered with the query visible.
  3. The client will get the query data and show the spinner while doing this.


When you look at the flow that the client follows, you see in the latest step that the client will query the data and therefor perform another call to the service. This is not the most optimal solution when you’re working with a high latency connection. Luckily, there is a way to bypass this. How do we do this? Let’s get back to our little example.

Add a POActions class for the PO we want to return. In this class override the OnLoad method. Inside this method, we can tell Vidyano to load the data of the query as follows:

public override void OnLoad(PersistentObject obj, PersistentObject parent)
	base.OnLoad(obj, parent);
	obj.Queries.ToList().ForEach(q => q.IsIncludedInParentObject = true);

that’s it!

  • Robby

    I had to set the attribute Is hidden of the PO MyQueryPO to false in order to get the query directly

    and the line "obj.Queries.ToList().ForEach(q => q.IsIncludedInParentObject = true);" should be in the OnConstruct method of the MyQueryPOActions class