Skip to content

Recognized Where-Expressions

This page catalogues all kinds of lambda expressions supported by ExRam.Gremlinq in various Where-operators.

Basic predicates

Property equality & inequality

Compare a property to a constant value.

C#
.Where(p => p.Age == 36)
.Where(p => p.Age != 36)
.Where(p => p.Name!.Value == "Some name")
Comparison operators

Standard relational operators on properties.

C#
.Where(p => p.Age > 36)
.Where(p => p.Age >= 36)
.Where(p => p.Age < 36)
.Where(p => p.Age <= 36)
Null checks

Check whether a property is or isn't null.

C#
.Where(p => p.Name == null)
.Where(p => p.Name != null)
.Where(p => p.Gender == null)
.Where(p => p.Gender != null)
Boolean properties

Direct boolean property evaluation, including negation.

C#
.Where(p => p.Enabled)
.Where(p => !p.Enabled)
.Where(p => p.Enabled == true)
.Where(p => p.Enabled == false)
Constant boolean expressions

Use a literal or captured boolean variable.

C#
.Where(p => true)
.Where(p => false)
.Where(p => someBoolVariable)

Logical operators

Logical AND (&&)

Combine multiple conditions with logical AND.

C#
.Where(p => p.Age == 36 && p.Name!.Value == "Hallo")
.Where(p => p.Age == 36 && p.Age == 42 && p.Age == 99)
Logical OR (||)

Combine multiple conditions with logical OR.

C#
.Where(p => p.Age == 36 || p.Age == 42)
.Where(p => p.Name!.Value == "Some name" || p.Age == 42)
Mixed AND / OR with grouping

Parenthesised sub-expressions mixing && and ||.

C#
.Where(p => p.Name!.Value == "Some name" && (p.Age == 42 || p.Age == 99))
.Where(p => p.Name == null && (p.Age == 42 || p.Age == 99))

Collection predicates

Collection .Contains() (value in collection)

Check whether a property value is contained in an in-memory collection.

C#
.Where(p => new[] { 36, 37, 38 }.Contains(p.Age))
.Where(p => new List<int> { 36, 37, 38 }.Contains(p.Age))
.Where(p => someEnumerable.Contains(p.Age))

Negated:

C#
.Where(p => !new[] { 36, 37, 38 }.Contains(p.Age))
.Where(p => !someEnumerable.Contains(p.Age))
Array / collection property .Contains()

Check whether an array property on the element contains a specific value.

C#
.Where(p => p.PhoneNumbers!.Contains("+4912345"))
.Where(p => !p.PhoneNumbers!.Contains("+4912345"))
Array / collection property .Any()

Test whether an array property has any elements.

C#
.Where(p => p.PhoneNumbers!.Any())
.Where(p => !p.PhoneNumbers!.Any())
Array / collection property .Length

Compare the length of an array property.

C#
.Where(p => p.PhoneNumbers!.Length == 3)
Set intersection (.Intersect().Any())

Check whether two collections share any common element, in either direction.

C#
.Where(p => p.PhoneNumbers!.Intersect(new[] { "+4912345", "+4923456" }).Any())
.Where(p => new[] { "+4912345", "+4923456" }.Intersect(p.PhoneNumbers!).Any())

Negated:

C#
.Where(p => !p.PhoneNumbers!.Intersect(new[] { "+4912345", "+4923456" }).Any())
.Where(p => !new[] { "+4912345", "+4923456" }.Intersect(p.PhoneNumbers!).Any())

String predicates

string.StartsWith

Match a string prefix, optionally case-insensitive or with a char.

C#
.Where(p => p.CountryCallingCode!.StartsWith("+49"))
.Where(p => p.CountryCallingCode!.StartsWith("+49", StringComparison.OrdinalIgnoreCase))
.Where(p => p.CountryCallingCode!.StartsWith('+'))
string.EndsWith

Match a string suffix, optionally case-insensitive.

C#
.Where(p => p.CountryCallingCode!.EndsWith("7890"))
.Where(p => p.CountryCallingCode!.EndsWith("7890", StringComparison.OrdinalIgnoreCase))
string.Contains

Check for a substring, optionally case-insensitive.

C#
.Where(p => p.CountryCallingCode!.Contains("456"))
.Where(p => p.CountryCallingCode!.Contains("456", StringComparison.OrdinalIgnoreCase))
string.Equals with StringComparison

Explicit string equality with a comparison mode.

C#
.Where(p => p.CountryCallingCode!.Equals("+49123"))
.Where(p => p.CountryCallingCode!.Equals("+49123", StringComparison.OrdinalIgnoreCase))
object.Equals

Use the Equals instance method for comparison.

C#
.Where(p => p.Age.Equals(36))
Reversed string matching (constant on the left)

The constant is on the left and the property is the argument — used for prefix-of or superstring-of semantics.

C#
.Where(p => "+49123".StartsWith(p.CountryCallingCode!))
.Where(p => "+49123".StartsWith(p.CountryCallingCode!, StringComparison.OrdinalIgnoreCase))
.Where(p => someString.StartsWith(p.CountryCallingCode!))
.Where(p => "+49123".Contains(p.CountryCallingCode!))

Also works with sub-expressions on the left-hand side:

C#
.Where(p => str.Substring(0, 6).StartsWith(p.CountryCallingCode!))
.Where(p => uri.ToString().StartsWith(p.CountryCallingCode!))
string.CompareTo

Lexicographic comparison via CompareTo. All comparison operators against the CompareTo return value are supported.

C#
.Where(p => p.Name!.Value.CompareTo("Some name") == 0)   // equals
.Where(p => p.Name!.Value.CompareTo("Some name") > 0)    // greater
.Where(p => p.Name!.Value.CompareTo("Some name") < 0)    // less
.Where(p => p.Name!.Value.CompareTo("Some name") >= 0)   // greater or equal
.Where(p => p.Name!.Value.CompareTo("Some name") <= 0)   // less or equal
.Where(p => p.Name!.Value.CompareTo("Some name") != 0)   // not equal

Also works through the IComparable<T> interface:

C#
.Where(p => ((IComparable<string>)p.Name!.Value).CompareTo("Some name") >= 0)
.ToString() on a property

Call ToString() on a property and compare the result.

C#
.Where(p => p.CountryCallingCode!.ToString() == "some_string")

Advanced predicates

Property-to-property comparisons

Compare two properties on the same element.

C#
.Where(p => p.Name!.Value == p.CountryCallingCode)
.Where(p => p.IntProperty1 > p.IntProperty2)
Id comparisons & cast expressions

Compare the element Id, including explicit casts.

C#
.Where(p => p.Id == (object)1)
.Where(p => (int)p.Id! == 1)
.Where(p => (string?)p.Id == someGuidString)
.Where(p => (object)p.Age == (object)36)
DateTime / DateTimeOffset comparisons

Compare date-typed properties to DateTime or DateTimeOffset values.

C#
.Where(p => p.RegistrationDate!.Value == dateTime)
.Where(p => p.RegistrationDate!.Value == DateTime.MinValue)
.Where(p => p.Properties!.ValidFrom == new DateTimeOffset(2019, 1, 1, 1, 0, 0, TimeSpan.Zero))
.Where(p => p.Properties!.ValidFrom >= new DateTimeOffset(2019, 1, 1, 1, 0, 0, TimeSpan.Zero))
Captured variables & closures

Reference local variables, parameters, or expressions computed outside the lambda.

C#
.Where(p => p.Age == i + i)
.Where(p => p.Id == (object)localVariable)
.Where(p => p.Id == (object)localVariable.Value)
.Where(p => someEnumerable.Contains(p.Age))
Anonymous-object property in closure

Use a property from a captured anonymous object as the boolean predicate.

C#
var anon = new { Prop = true };
.Where(p => anon.Prop)
StepLabel / cross-traversal references

Compare properties against values captured earlier in the traversal via step labels (.As() / StepLabel).

C#
.Where(p => p.IetfLanguageTag == stepLabel.Value)
.Where(p => p.Age >= anotherStepLabel.Value)
.Where(p => p.Age >= otherPerson.Value.Age)
Sub-traversals in Where

Use a nested anonymous traversal as a filter predicate.

C#
.Where(_ => _.Out())
.Where(_ => _.Out<LivesIn>())
.Where(_ => _.OfType<Authority>())
.Where(_ => _.Identity())
.Where(_ => _.None())
.Where(_ => _.Properties())
Nested Where on sub-traversals (value filtering)

Apply Where inside a sub-traversal to filter by traversed values.

C#
.Where(__ => __
    .Values(x => x.Age)
    .Where(age => age > 36))

.Where(__ => __
    .Values(x => x.Name!.Value)
    .Where(x => x == "hallo1")
    .Where(x => x == "hallo2"))
Null / AND / OR on value-type sub-traversals

Null checks, AND, and OR on scalar sub-traversal results.

C#
.Where(__ => __.Values(x => x.Name!.Value).Where(x => x == null!))
.Where(__ => __.Values(x => x.Name!.Value).Where(x => x != null! && x == "hello"))
.Where(__ => __.Values(x => x.Name!.Value).Where(x => x != null! || x == "hello"))
VertexProperty metadata access

Filter on VertexProperty key, label, value, or meta-properties.

C#
.Where(vp => vp.Key == "someKey")
.Where(vp => vp.Label == "label")
.Where(vp => vp.Label != "label")
.Where(vp => (int)vp.Value < 10)
.Where(vp => vp.Properties!["MetaKey"] == "MetaValue")
.Where(vp => (int)vp.Properties!["MetaKey"] < 100)
.Values() sub-traversal in Where

Project a property inside a filter to assert its existence or shape.

C#
.Where(x => x.Values(y => y.Age))
.Where(x => x.Values(y => y.Gender!))
Projected tuple element access

After a .Project().ToTuple().By(...) projection, the traversal yields tuples. Where can filter on individual elements of these tuples via .Item1, .Item2, etc.

C#
_g
    .Inject(42)
    .Project(__ => __
        .ToTuple()
        .By(__ => __.Constant("item1"))
        .By(__ => __.Fold()))
    .Where(x => x.Item2.Length == 3)

In this example, Item2 refers to the second projected column (the result of .Fold(), which is an array). The .Length comparison is an array-length filter applied to that specific tuple element.