/ Assembly List / LJCDBMessage / DbFilters

Namespace - LJCDBMessage


Syntax

C#
public class DbFilters : List<DbFilter>

Represents a collection of DbFilter objects. (E)

Remarks

The common collection static methods are: HasItems(), SQLSoundexFilters() and SoundexFilters().
The collection contains a copy constructor.
The common collection instance methods are: Add() + 1 overload and Clone().

Constructor
#ctor Initializes an object instance.
#ctor The Copy constructor.

Collection
Add Creates and adds the element from the supplied values.
Add Creates and adds the element from the supplied values.
Clone Clones the structure of the object.

Other Public Methods
SoundexFilters Creates the Soundex filters from the supplied values.
SQLSoundexFilters Creates the SQL Soundex filters from the supplied values.
7 Methods

Example

C#
using LJCDBMessage;
      
// Create the Conditions collection and Condition objects.
DbConditions dbConditions = new DbConditions();
DbCondition dbCondition = new DbCondition()
{
  FirstValue = "Name",
  ComparisonOperator = "=",
  SecondValue = "John"
};
dbConditions.Add(dbCondition);
      
// Create the ConditionSet and add the Conditions collection.
DbConditionSet dbConditionSet = new DbConditionSet()
{
  // The boolean operator is added before each condition except the first.
  BooleanOperator = "and",
  Conditions = dbConditions
};
      
// Create the Filter and add the ConditionSet.
DbFilter dbFilter = new DbFilter()
{
  Name = "Main Filter",
      
  // The boolean operator is added before each filter except the first.
  BooleanOperator = "and",
  ConditionSet = dbConditionSet
};
      
// Create the Filters collection and add the Filter.
DbFilters dbFilters = new DbFilters();
dbFilters.Add(dbFilter);
      
// Shortcut using object initialization, only required values and defaults.
DbFilter dbFilter = new DbFilter();
DbConditions conditions = dbFilter.ConditionSet.Conditions;
conditions.Add("FirstName", "'John'");
conditions.Add("LastName", "'Smith'");
DbFilters dbFilters = new DbFilters
{
  dbFilter
};
      
// The Data Service creates the following SQL from this request which.
// includes the DbFilters object.
DbRequest dbRequest = new DbRequest("Select", "Person")
{
  DataConfigName = "PersonData",
  Columns = new DbColumns() { {"Name" }},
  Filters = dbFilters
};
      
// select
//  [Person].[Name]
// from [Person]
// where ((FirstName = 'John' and LastName = 'Smith'))
      
// Adding an "or" filter.
DbFilter secondFilter = new DbFilter
{
  BooleanOperator = "or"
};
DbConditions secondConditions = secondFilter.ConditionSet.Conditions;
secondConditions.Add("Street", "'Somewhere%'", "like");
dbFilters.Add(secondFilter);
      
// where ((FirstName = 'John' and LastName = 'Smith'))
//  or ((Street like 'Somewhere%'))
      
// If the second filter is incuded inside the first as in the following
// example,then the second filter conditions are grouped with the first
// filter conditions.
dbFilter.Filters.Add(secondFilter);
      
// where ((FirstName = 'John' and LastName = 'Smith')
//  or (Street like 'Somewhere%'))

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.