RelationCollectionAdd(Entity, RelationType) Method
Adds a relation toe this collection
Namespace: Firefly.Box.AdvancedAssembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
public Relation Add(
Entity entity,
RelationType type
)
Public Function Add (
entity As Entity,
type As RelationType
) As Relation
member Add :
entity : Entity *
type : RelationType -> Relation
- entity Entity
- The entity from which to extract the related row
- type RelationType
- The type of the relation
Relation This example demonstrates the usage of FetchingRowsWithRelations
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
Entityusing 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");
}
}
}