public class Relation
Public Class Relation
type Relation = class end
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");
}
}
}
Relation(Entity) | Initializes a new instance of the Relation class. |
Relation(Entity, FilterBase) | Initializes a new instance of the Relation class. |
Relation(Entity, RelationType) | Initializes a new instance of the Relation class. |
Relation(Entity, Sort) | Initializes a new instance of the Relation class. |
Relation(Entity, FilterBase, Sort) | Initializes a new instance of the Relation class. |
Relation(Entity, RelationType, FilterBase) | Initializes a new instance of the Relation class. |
Relation(Entity, RelationType, Sort) | Initializes a new instance of the Relation class. |
Relation(Entity, RelationType, FilterBase, Sort) | Initializes a new instance of the Relation class. |
__RecomputePath | |
Enabled | Determines if this Relation is enabled. |
From | Gets the value determining the Relation's from |
OrderBy | Gets or sets the value determining order in which the rows are ordered |
RecomputeOnNotifyRowWasFoundToParentColumn | |
RowFound | Returns true if this relation points to an existing row |
Type | Gets this Relation's type |
Where | The FilterCollection according to which rows will be loaded in this Relation |
AddAllColumns | Adds all the columns of the relations entity to the Columns collection |
Associate | Allows for columns that are not associated with the Relation's From to be included in the Relation reevaluation. |
BindEnabled | Sets an expression that will determine the value of the Enabled property. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
NotifyRowWasFoundTo(BoolColumn) | Determines a column that will be set whenever the Relation is loaded or reloaded. |
NotifyRowWasFoundTo(NumberColumn) | Determines a column that will be set whenever the Relation is loaded or reloaded. |
SetOriginalValuesForColumns | |
ToString | Returns a string that represents the current object. (Inherited from Object) |
Load | Occurs whenever a row is loaded to this Relation |