Query filters

Filtering is designed to support scenarios where you like to filter results with some dynamic condition - for example, using user assigned filters. Filters are implemented with extension methods and therefore you must include the namespace NSQLObjects.Filter in your source file before using filters.
using NSQLObjects.Filter;

You apply filters to queries before loading the actual content. For example:
using (var ctx = SqlDataContext.CreateContext()) {
    CustomerProducts cu = new CustomerProducts () { CID  = <customer id> };
    cu.IsEQ(row => row.ProductID, <product id>);

This query will now only load rows where ProductID is equal to given product ID. The syntax for the predefined filters has a column reference expression (row => row.ProductID in example) as the first parameter. The second parameter is the actual value (if applicable).

All filters are appended to the query and executed inside database server. If you set multiple filters, all filters will be applied at the same time (filters are joined with the and operand).

Predefined filters are.

Filter Description
IsEQ Column value is equal to given value
IsNE Column value is not equal to given value
IsLT Column value is less than given value
IsLE Column value is less or equal than given value
IsGT Column value is greater than given value
IsGE Column value is greater or equal than given value
IsNull Column value is null
IsNotNull Column value is not null
IsLike Column value is like given value.

You can also define your own filters with extension methods.
Query sorting

Last edited Oct 26, 2010 at 8:56 AM by nolics, version 3


No comments yet.