Working with Fluent Query Result Sets

Use the .field() method to get field values from a row in the result set.

Copy
var E = server.query.getAlias('entity');

var rows = server.query.from('entity', E)
.top(5)
.execute();

let output = '\n\nThe following entities were found:\n';

rows.map(function(r)
{
output += (' ' + r.field(E.Name) + '\n')
});

log(output);

The code above will log an output similar to the following in the trace_roll.log file:

Copy
-[START]---------------------------------------
Timestamp: 7/2/2020 1:15:34 PM
 Message: INFO [CID=200524bb-8d28-4079-80c3-a003a9ecad7d] 

The following entities were found:
 entityBWTransitionActionGroup
 SystemUserSecurityRole
 BW
 optionset
 lookupCorrelationAttribute

 Severity: Information
-[END]---------------------------------------

Map result sets to POCO objects

Use the .executeAndMap() method to map a fluent query result set to an entity alias. This creates a plain old CLR object (POCO) which allows you to access field values as object properties, instead of using the .field() method.

Copy
var E = server.query.getAlias('entity');

var rows = server.query.from('entity', E)
.top(5)
.executeAndMap(E);

let output = '\n\nThe following entities were found:\n';

rows.map(function(r)
{
output += (' ' + r.Name) + '\n')
});

log(output);

To map a fluent query result set to multiple entity aliases, use the .executeAndMapComplex() method.

Copy
var E = server.query.getAlias('entity');
var A = server.query.getAlias('attribute');

var rows = server.query.from('entity', E)
.innerJoin('attribute', A)
.on(E.EntityId.eq(A.EntityId))
.top(20)
.selectColumns(
E.Name,
A.Name)
.executeAndMapComplex({ entity : E,  attribute : A});

rows.map(function(r)
{
var entityName = r.entity.Name;
var attrName   = r.attribute.Name;

// do

});