UIControllerWhere Property

Gets the value determining the filter that will be applied on the rows of this UIController.

Definition

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

Property Value

FilterCollection

Remarks

Only rows that matches this filter will be processed by this UIController.
When using the overload of the Add Method that gets a FuncTResult condition, there is a performance penalty as this condition is evaluated in memory, and not sent to the database.
Performance tip - Any Where filter that is based only on columns that are part of the Task Main Query(*) will be performed by the database.
Parts of the {0} that are not part of the Task Main Query
will be performed in memory, resulting in a performance penalty in cases where many rows are involved
(*)Task Main Query - includes the entity defined in the From property, and any entity that is part of a relation (as defined in the Relations property collection) that is of type Join or OuterJoin

Example

Filter Usage
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 Firefly.Box.Data.Advanced;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class WhereUsage
    {
        [Test]
        public void SimpleWhere()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();

            var bp = new BusinessProcess
                         {
                             From = employees
                         };
            bp.Where.Add(employees.JobLevel.IsEqualTo(150));
            bp.Run();
            bp.Counter.ShouldBe(3);
        }
        [Test]
        public void AddingTwoFiltersBehavesAsAndWould()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();

            var bp = new BusinessProcess
            {
                From = employees
            };
            bp.Where.Add(employees.JobLevel.IsEqualTo(150));
            bp.Where.Add(employees.JobId.IsLessThan(9));
            bp.Run();
            bp.Counter.ShouldBe(1);
        }
        [Test]
        public void UsingAndAndOr()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();

            var bp = new BusinessProcess
            {
                From = employees
            };
            bp.Where.Add(employees.JobLevel.IsEqualTo(150).And(
                        employees.JobId.IsLessThan(9).Or(
                        employees.MiddleInitial.IsEqualTo("C"))));
            bp.Run();
            bp.Counter.ShouldBe(2);
        }
        [Test]
        public void SendingDirectStringToTheDB()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();
            var bp = new BusinessProcess
                         {
                             From = employees
                         };
            bp.Where.Add("{0} in ({1},{2},{3})",employees.MiddleInitial, "M", "R", "A");
            bp.Run();
            bp.Counter.ShouldBe(9);
        }
        [Test]
        public void UsingCustomInMemoryFilter()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();
            var bp = new BusinessProcess
            {
                From = employees
            };
            //This has a slight performance penalty as this condition is evaluated in memory, and not by the database
            bp.Where.Add(() => employees.MiddleInitial == "M" || employees.MiddleInitial == "R" || employees.MiddleInitial == "A");
            bp.Run();
            bp.Counter.ShouldBe(9);
        }
        [Test]
        public void UsingAPreDefinedFilter()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();
            var bp = new BusinessProcess
            {
                From = employees
            };
            FilterCollection filter = new FilterCollection();
            filter.Add(employees.JobLevel.IsEqualTo(150));
            filter.Add(employees.JobId.IsLessThan(9));

            bp.Where.Add(filter);
            bp.Run();
            bp.Counter.ShouldBe(1);
        }
    }
}

See Also