[This is preliminary documentation and is subject to change.]

Performs the specified action on each row that matches the Where property filter.

Namespace:  Firefly.Box
Assembly:  Firefly.Box (in Firefly.Box.dll) Version: 3.4.23.6473 (3.4.23.6473)

Syntax

C#
public void ForEachRow(
	Action action
)
Visual Basic (Declaration)
Public Sub ForEachRow ( _
	action As Action _
)
Visual C++
public:
void ForEachRow(
	Action^ action
)

Parameters

action
Type: System..::.Action
The Action to be performed for each row

Remarks

Created for ease of use scenarios.
Most simple business operations needs to perform an action for each row that matches the filter.
Behaves the same way as registering that action to the LeaveRow event, and invoking the Run()()() method.

Examples

This example demonstrates both ForEachRow and ForFirstRow
This example is in the form of Unit Tests. It references the NUnit framework. This framework can be downloaded from www.NUnit.org. For more information about unit testing visit: www.NUnit.org.
This example is based on test data. The code for the entities included in this test data can be found in the documentation of Entity
CopyC#
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class ForEachRow
    {
        [Test]
        public void SumOfMinLevel()
        {
            var jobs = new Pubs.Jobs();
            jobs.InitializeWithTestData();

            int totalMinLevel = 0;

            var bp = new BusinessProcess
                         {
                             From = jobs
                         };
            bp.ForEachRow(() => totalMinLevel += jobs.MinLevel);
            totalMinLevel.ShouldBe(1370);
        }


        [Test]
        public void ForEachRowDemo()
        {
            var jobs = new Pubs.Jobs();
            jobs.InitializeWithTestData();
            string jobTitles = "";

            var bp = new BusinessProcess
                         {
                             From = jobs,
                         };
            bp.Where.Add(jobs.Id.IsLessOrEqualTo(3));
            bp.ForEachRow(() =>
                              {
                                  if (jobTitles.Length > 0)
                                      jobTitles += ", ";
                                  jobTitles += jobs.Description.Value.TrimEnd();
                              });

            jobTitles.ShouldBe(
                "New Hire - Job not specified, Chief Executive Officer, Business Operations Manager"
                );
        }
        [Test]
        public void AchievingTheBehaviourOfForEachRowWithLeaveRow()
        {
            var jobs = new Pubs.Jobs();
            jobs.InitializeWithTestData();
            string jobTitles = "";

            var bp = new BusinessProcess
            {
                From = jobs,
            };
            bp.Where.Add(jobs.Id.IsLessOrEqualTo(3));
            bp.LeaveRow += () =>
            {
                if (jobTitles.Length > 0)
                    jobTitles += ", ";
                jobTitles += jobs.Description.Value.TrimEnd();
            };
            bp.Run();

            jobTitles.ShouldBe(
                "New Hire - Job not specified, Chief Executive Officer, Business Operations Manager"
                );
        }
        [Test]
        public void ForFirstRowDemo()
        {
            var jobs = new Pubs.Jobs();
            jobs.InitializeWithTestData();
            string jobTitles = "";

            var bp = new BusinessProcess
            {
                From = jobs,
            };
            bp.Where.Add(jobs.Id.IsLessOrEqualTo(3));
            bp.ForFirstRow(() =>
            {
                if (jobTitles.Length > 0)
                    jobTitles+=", ";
                jobTitles+=jobs.Description.Value.TrimEnd();
            });

            jobTitles.ShouldBe("New Hire - Job not specified");
        }
        [Test]
        public void AchievingTheBehaviourOfForFirstRowWithLeaveRowEvent()
        {
            var jobs = new Pubs.Jobs();
            jobs.InitializeWithTestData();
            string jobTitles = "";

            var bp = new BusinessProcess
            {
                From = jobs,
            };
            bp.Where.Add(jobs.Id.IsLessOrEqualTo(3));
            bp.LeaveRow += () =>
            {
                if (jobTitles.Length > 0)
                    jobTitles+=", ";
                jobTitles+=jobs.Description.Value.TrimEnd();
            };
            bp.Exit(ExitTiming.AfterRow);
            bp.Run();

            jobTitles.ShouldBe("New Hire - Job not specified");
        }
    }
}

See Also