You can use the following examples of criteria to build your dynamic query using the DAL query engine.
Example 1. You can query for tags where the Name property is set as "TAG1_*".
Dim lobjDynamicQuery As New DynamicQuery()
lobjDynamicQuerylobjDynamicQuery.Query.Criteria = New ObjectCriteria(Function(o)
o.HasInterface("IDEVTag") And o.Name = "TAG1_*")
Dim lcolResults As IObjectDictionary = lobjDynamicQuery.ExecuteToIObjectDictionary()
Example 2. You can also query for IObject properties, such as Name, UID, and CreationDate, or you can specify a property definition UID.
lobjDynamicQuery.Query.Criteria = New ObjectCriteria(Function(o) o.HasInterface("IDEVTag") And o.Name = "TAG1_*" And o.Property("DEVWeight").FloatValue = 3.3 And Not o.Name = "*0")
This query returns results for IDEVTag, where the property name begins with "TAG1_", the DEVWeight is 3.3, and the name does not end in a "0".
Example 3. You can query for IDEVTags, where the property name begins with "TAG1_", and the name does not end in a "0".
lobjDynamicQuery.Query.Criteria = New ObjectCriteria(Function(o) o.HasInterface("IDEVTag") And o.Name = "TAG1_*" And Not o.Name = "*0")
Supported criteria types
The following types of criteria are supported.
Criteria Type |
Description |
---|---|
Null/Nothing |
A null object will be treated as if you are testing for a null value in the database. This does not test for the non-existence of a property. It matches where a property may have a null or empty value in the database. Use Exists or DoesNotExist operators instead. |
IEnumerable<string>, params string[] |
A string array allows you to use multiple string items for the InList and NotInList operators. |
String |
A string allows a sequence of characters, either as a literal constant or as a variable. |
Float |
A float defines a variable with a fractional value. |
Integer |
An integer is a whole number. |
Double |
A double is a larger float that contains larger and more precise numbers. |
Brackets
The DAL query engine allows you to build a dynamic query with multiple criteria, separated using the enclosing brackets ( or ). For example, you can return all tags starting with Tag1 and Tag2, as follows:
lobjDynamicQuery.Query.Criteria = ObjectCriteria.(Function(o)
(o.HasInterface("IDEVTag") And o.Name = "TAG1_*")
Or
(o.HasInterface("IDEVTag") And o.Name = "TAG2_*")
The example shows two sets of brackets joined by an Or. No results would be returned if the brackets were joined by an And, because an object cannot start with Tag1 and Tag2 simultaneously.
Operators
You can simplify query criteria further using overloaded operators to compare property values. For example:
ObjectCriteria.(Function(o)
(o.HasInterface("IDEVTag") And o.Name = "TAG1_*")
You can also use other common overloaded operators to simplify the queries:
VB operators: = , <>, >, <, =<, >=
C# operators: ==, !=, &&, ||, >, <, >=, =<
You can match against an array of values by applying the InList operator. The full list of operators are as follows:
Operator |
Description |
Example |
---|---|---|
EqualTo |
Matches the criteria provided. |
o.Name = "TAG1_*"TAG1_*") |
NotEqualTo |
Does not match the criteria provided. |
o.Name <> "TAG1_*" |
Exists |
Matches the properties that exist, but they have no values or their values are not required. |
o.Property("Name").Exists |
DoesNotExist |
Matches properties that do not exist or their values are not required. |
o.Property("Name").DoesNotExists |
NullOrEmpty |
Returns any matches where the value is null or empty. |
o.Name.NullOrEmpty |
NotNullOrEmpty |
Returns any matches where the value is not null or empty. |
o.Name.NotNullOrEmpty |
InList |
Any value present within an array of values. |
o.Property("ObjDefUID").InList(lobjFTREnabledClassdefs.Select(Function(x) x.UID)) |
NotInList |
Any value not present within an array of values. |
o.Property("ObjDefUID").NotInList(lobjFTREnabledClassdefs.Select(Function(x) x.UID)) |
GreaterThan |
Any value greater than but not including the given value. |
o.Property("LASTUPDATEDDATE") > lstrDelayByDate |
LessThan |
Any value less than but not including the given value. |
o.Property("LASTUPDATEDDATE") < lstrDelayByDate |
GreaterThanOrEqualTo |
Any value greater than or the same as the given value. |
o.Property("LASTUPDATEDDATE") >= lstrDelayByDate |
LessThanOrEqualTo |
Any value less than or the same as the given value. |
o.Property("LASTUPDATEDDATE") <= lstrDelayByDate |
Contains |
Any values that contains specified criteria. |
o.Name.Contains("IsItHere") |
StartsWith |
Any values that starts with the specified criteria. |
o.Name.StartsWith("StartsHere") |
EndsWith |
Any values that ends with the specified criteria. |
o.Name.EndsWith("EndsHere") |