Skip to main content

Dynamic Querying Over Service Boundaries

The ELEFLEX® platform needed a way of dynamic querying of information that crosses application boundaries and could also be leveraged against varying back-end storage mechanisms to support the RF3 Dynamic SOA Data Manipulation requirement. The solution was to build a simple model that could contain queryable expressions that would then be translated to dynamic Linq statements using the open source project LinqKit

Creating query expressions is done with the Eleflex.StorageQueryBuilder object. It contains standard methods and expressions to develop complex queries that can be transferred and translated easily. Because the information may pass application boundaries, the property name and data associated with the filter are stored as string values. The translation engine will parse the values to their native datatypes as needed.

Name Description
Aggregate Perform an aggregate operation against a property including Average, BinaryChecksum, Checksum, Count, Minimum, Maximum, and Sum
Between Perform a comparison between a high and low value
Compare This includes IsEqual, NotEqual, GreaterThan, GreaterThanOrEqual, LessThan, and LessThanOrEqual.
Distinct Get a distinct item set
Expression Filter comparers including And, Or, BeginExpression and EndExpression. It is important to note that if an expression combiner (as in “And()” as well as “Or()”) is not defined between two where clause filters, the engine will automatically use an “And()” filter when combining the filter tree.
Like Comparison filter for StartsWith, EndsWith, Contains() and notcontains() operations using wild cards
Null Determine if the property value is null or not null
PropertyComparison Allows comparisons between properties
Select Filter defines which properties are to be returned from a response. By default, all properties are selected for queries.
Set Filter for InSet, NotInSet, defines a set of values that a property must value or not have
Sort Determines the sort direction for a specific property
Paging Filter that defines the number per page and page number of items that should be returned

The following example demonstrates how to create a query to find all roles with the name equal to “TestUser” and have an EffectiveStartDate of null or an EffectiveStartDate in the past.

    
//CREATE REPOSITORY SERVICE
var service = ObjectLocator.Current.GetInstance<ISecurityRoleBusinessRepository>();
//CREATE BUILDER
StorageQueryBuilder builder = new StorageQueryBuilder();
//WHERE Name = “TestUser” AND have an effective start date of null or a date in the past
builder
  .IsEqual("Name", "TestUser")
  .And()
  .BeginExpression()
  .IsNull("EffectiveStartDate")
  .Or()
  .IsLessThanOrEqual("EffectiveStartDate", DateTimeOffset.UtcNow.ToString())
  .EndExpression();
//CALL SERVICE
var respRoles = service.Query(new ResponseItem<IStorageQuery>(){Item = builder.GetStorageQuery()});