Relation Class

Represents a many to one relation some times called a one to one relation.

Definition

Namespace: Firefly.Box
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public class Relation
Inheritance
Object    Relation

Remarks

If more than one row matches the criteria the first matching row will be used

Example

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 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");
        }

    }
}

Constructors

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.

Properties

__RecomputePath 
Enabled Determines if this Relation is enabled.
FromGets 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

Methods

AddAllColumnsAdds 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.
BindEnabledSets an expression that will determine the value of the Enabled property.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
MemberwiseCloneCreates 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 
ToStringReturns a string that represents the current object.
(Inherited from Object)

Events

Load Occurs whenever a row is loaded to this Relation

See Also