GORMDocs
CORE CONCEPTS

Think in topology, not hidden joins.

GORM keeps graph structure explicit. A node is a domain entity, an edge is a typed relationship, and traversal expresses how a query moves through that topology.

MENTAL MODEL

Three layers, one model

DOMAIN

CLR types

Your entities describe the domain: services, people, projects, devices and their data.

GRAPH

Nodes + edges

Types opt into graph identity and relationships. Direction and edge type become queryable facts.

PROVIDER

SQL Server Graph

GORM translates graph intent to node tables, edge tables, predicates and SQL Server Graph MATCH expressions.

NODES

Nodes are ordinary domain entities with graph identity

A node participates in graph relationships while keeping ordinary scalar properties. Id is the default identity convention.

public sealed class ServiceNode : Node
{
    public string Name { get; set; } = string.Empty;
    public ServiceState State { get; set; }
    public string? Region { get; set; }
}
Design ruleUse a node because the entity participates in meaningful topology, not merely because it is stored in SQL.
EDGES

An edge is data, not just a foreign key

Edges can have identity and properties of their own. This is useful when the relationship itself carries semantics such as priority, role, weight or provenance.

public sealed class DependsOnEdge : Edge
{
    public DependencyKind Kind { get; set; }
    public bool IsCritical { get; set; }
}
RELATIONSHIPS

Direction is explicit

For api -(DependsOn)-> database, outgoing traversal from api returns dependencies; incoming traversal from database returns dependents.

OUTGOING
context.Set<ServiceNode>()
    .Where(x => x.Id == apiId)
    .Outgoing<DependsOnEdge, ServiceNode>()
INCOMING
context.Set<ServiceNode>()
    .Where(x => x.Id == databaseId)
    .Incoming<DependsOnEdge, ServiceNode>()

Traversal answers a path question. Include answers an object-materialization question. They are related but intentionally different tools.

CHANGE TRACKING

Topology changes are first-class changes

A graph unit of work may contain scalar node changes, edge-property changes, new connections and disconnections. GORM treats those as explicit persistence work instead of hiding them behind collection manipulation.

Node modifiedScalar state changed.
Edge modifiedRelationship metadata changed.
ConnectA new topology relation is created.
DisconnectAn existing topology relation is removed.
TEMPORAL MODEL

History includes topology

Historical inspection is only useful if node history and edge history can be reasoned about together. Point-in-time graph queries should reconstruct what was connected at that moment.

var snapshot = await context.Set<ServiceNode>()
    .AsOf(incidentStartedAt)
    .ToListAsync();
PROVIDER BOUNDARY

Same model does not mean identical providers

The in-memory execution path exists for deterministic tests. SQL Server Graph remains the production persistence semantics that provider-level integration tests must validate.

Important

Never use a passing in-memory test as proof that provider-specific SQL translation, concurrency or temporal behavior is correct.