2

I have a .NET object which is a collection, for example an Employee object containing list of employees.

I need to pass the same to the rules engine to do the looping inside the rule file.

Can you please help me with code to the same from .NET as well looping in xbre file. I have successfully passed an object with single record. However need to pass collection.

David Dossot
  • 33,403
  • 4
  • 38
  • 72

1 Answers1

3

I suggest you pass the EmployeeWrapper object itself to NxBRE using the standard approach:

bre.RuleContext.SetObject("EmployeeWrapper", employeeWrapper);

then reflectively extract the list of employees with:

<ObjectLookup id="Employees" objectId="EmployeeWrapper" member="Employees" />

assuming the EmployeeWrapper object has a property named Employees which returns the collection of employees.

Then use a ForEach block to iterate the employees:

<ForEach id="Employee" valueId="Employees">
    ...
</ForEach>
David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • @David. Is it possible to get this collection like array, for example someting like `` , foreach solution cant resolve my problem. – vahid kargar Jun 12 '17 at 05:36
  • 1
    @vahidkargar The `NxBRE.Util.DataAccess#GetArrayColumnValue` static helper should allow you to get an array value. See example here: https://github.com/ddossot/NxBRE/blob/master/NxBRE3/Rulefiles/test.xbre#L771-L774 – David Dossot Jun 12 '17 at 18:21