Curiosity

LINQ Integration

Curiosity's query system integrates with standard C# LINQ (Language Integrated Query).

The Query interface provides a fluent builder for executing operations on the graph engine. However, once you retrieve results, you often need to perform further processing in memory.

AsEnumerable() and Standard LINQ

The AsEnumerable() method terminates the graph query and returns an IEnumerable<ReadOnlyNode>. From this point on, you can use standard LINQ methods.

var nodes = Graph.Query()
    .StartAt("Person")
    .AsEnumerable();

// Use standard LINQ
var sortedNames = nodes
    .Where(n => n.GetInt("age") > 30) // In-memory filtering
    .Select(n => ( Name: n.GetString("name"), Age: n.GetInt("age") )) // Projection to Tuple
    .OrderBy(x => x.Name) // In-memory sorting
    .ToList();
Performance Note

Prefer using Query methods like WhereString or SortBy... whenever possible. These execute within the graph engine and can utilize indexes, whereas LINQ operations happen in memory after fetching the data.

Engine-side predicates

When a filter has to run on a field value rather than an index, keep it on the query with Where(...) instead of materializing first. The strongly-typed Where<T>(field, predicate) overload casts the field value to T before your predicate runs, so the in-memory n => n.GetInt("age") > 30 step above becomes:

var sortedNames = Graph.Query()
    .StartAt("Person")
    .Where<int>("age", age => age > 30)   // evaluated on the engine
    .AsEnumerable()
    .Select(n => ( Name: n.GetString("name"), Age: n.GetInt("age") ))
    .OrderBy(x => x.Name)
    .ToList();
© 2026 Curiosity. All rights reserved.