FilterCollectionAdd(String, Object) Method

Adds a custom filter that will be sent directly to the database as a string.

Definition

Namespace: Firefly.Box.Data.Advanced
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public void Add(
	string customFilter,
	params Object[] args
)

Parameters

customFilter  String
 
args  Object
 

Remarks

Works similarly to the [String.Format(string,object[])].
Each value that will be sent in the customFilter parameter will undergo basic syntax transformations according to the following rules.
  • A column that is part of the query, will be sent as it's name (with an appropriate alias in cases of join).
  • Columns that are not part of the query, will be represented by their values
  • Objects implementing the ICustomFilterMember interface, will have their SendFilterTo(CustomFilterCollector) method called to supply the content
  • Numeric values will be sent as it
  • All other objects will be converted to string and sent as string parameters to the database.

Example

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

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class CustomFilterDemo
    {
        [Test]
        public void ColumnFromQuery()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();
            var bp = new BusinessProcess
            {
                From = employees
            };
            bp.Where.Add("{0} = 5", employees.JobId);
            bp.Run();
            bp.Counter.ShouldBe(7);
        }
        [Test]
        public void ColumnOutsideTheQuery()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();

            var jobToFilter = new NumberColumn();
            jobToFilter.Value = 5;
            var bp = new BusinessProcess
            {
                From = employees
            };
            bp.Where.Add("{0} = {1}", employees.JobId, jobToFilter);
            bp.Run();
            bp.Counter.ShouldBe(7);
        }
        [Test]
        public void UsageOfANumber()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();

            var bp = new BusinessProcess
            {
                From = employees
            };
            bp.Where.Add("{0} = {1}", employees.JobId, 5);
            bp.Run();
            bp.Counter.ShouldBe(7);
        }
        [Test]
        public void UsageOfAString()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();

            var bp = new BusinessProcess
            {
                From = employees
            };
            bp.Where.Add("{0} = {1}", employees.MiddleInitial, "M");
            bp.Run();
            bp.Counter.ShouldBe(3);
        }
    }
}

See Also