UIControllerRelations Property

Get this UIController relations

Definition

Namespace: Firefly.Box
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public RelationCollection Relations { get; }

Property Value

RelationCollection

Remarks

Relations are usually used to retrieve data from lookup entities.
Every relation that is add to the UIController's Relations property will be part of the reevaluation engine.
Relations Cache - To improve performance, whenever a is required by the relation, and that row was already used in other rows of this relation, it will be fetched from a cache, if all the following rules are met:
  • The Cached property of the relation's Entity is set to true,
  • The filter of the relation points to a unique row. The uniqueness is defined by the Entity's PrimaryKeyColumns property collection, or if it matches a Sort that is part of the Entity's Indexes property collection, that it's Unique property is set to true.
  • Such a row was already found in the relation, on previous rows

To find out more about the reevaluation engine, see Columns property.

Example

Fetching rows with relations
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
C#
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class FetchingRowsWithRelations
    {
        [Test]
        public void UsingRelationForALookupTable()
        {
            var employees = new Pubs.Employees();
            var jobs = new Pubs.Jobs();
            employees.InitializeWithTestData();
            jobs.InitializeWithTestData();

            var bp = new BusinessProcess
            {
                From = employees
            };
            bp.Relations.Add(jobs, jobs.Id.IsEqualTo(employees.JobId));
            string namesAndJobs = "";
            bp.ForEachRow(() =>
            {
                namesAndJobs += employees.LastName.Value.TrimEnd() + " - " +
                                jobs.Description.Value.TrimEnd() + "\n";
                if (bp.Counter == 5)
                    bp.Exit();
            });
            namesAndJobs.ShouldBe("Cruz - Productions Manager\n" +
                "Devon - Business Operations Manager\n" +
                "Roulet - Managing Editor\n" +
                "Domingues - Public Relations Manager\n" +
                "Hernadez - Publisher\n");
        }
        [Test]
        public void UsingRelationToFetchTheTopMostRow()
        {
            var jobs = new Pubs.Jobs();
            var employees = new Pubs.Employees();
            jobs.InitializeWithTestData();
            employees.InitializeWithTestData();

            var bp = new BusinessProcess()
            {
                From = jobs
            };
            //A relation that gets the employee with the highest joblevel in the matching job
            bp.Relations.Add(employees, employees.JobId.IsEqualTo(jobs.Id),
                new Sort(employees.JobLevel)).OrderBy.Reversed = true;

            string jobsAndEmployeesWithMaxLevel = "";

            bp.ForEachRow(() =>
            {
                jobsAndEmployeesWithMaxLevel += jobs.Description.ToString().TrimEnd() + " - " +
                                                employees.LastName.ToString().TrimEnd() + "\n";
            });
            jobsAndEmployeesWithMaxLevel.ShouldBe(
                "New Hire - Job not specified - \n" +
                "Chief Executive Officer - Cramer\n" +
                "Business Operations Manager - Devon\n" +
                "Chief Financial Officier - Chang\n" +
                "Publisher - Pontes\n" +
                "Managing Editor - Karttunen\n" +
                "Marketing Manager - Ibsen\n" +
                "Public Relations Manager - Saveley\n" +
                "Acquisitions Manager - Jablonski\n" +
                "Productions Manager - Sommer\n" +
                "Operations Manager - Mendel\n" +
                "Editor - Snyder\n" +
                "Sales Representative - O'Rourke\n" +
                "Designer - Josephs\n");
        }

    }
}

See Also