# Ingesting Data

Ingestion involves reading data from a source and mapping it to the graph structures you defined.

# Loading Source Data

You can read data from JSON files, APIs, or databases.

var devices = JsonConvert.DeserializeObject<DeviceJson[]>(File.ReadAllText("devices.json"));

# Adding Nodes

Use graph.TryAdd, graph.Update, or graph.AddOrUpdate to manage nodes in the graph.

# Node Persistence Methods

Method Behavior if node exists Behavior if node missing
TryAdd Returns existing node; does not update properties. Creates new node.
Update Updates properties of the existing node. Fails (throws exception or returns null).
AddOrUpdate Updates properties of the existing node. Creates new node.
foreach (var device in devices)
{
    // TryAdd is efficient for nodes that don't change once created (e.g. by Name)
    graph.TryAdd(new Nodes.Device() { Name = device.Name });
}

# Linking Nodes

Use graph.Link to create edges between nodes.

foreach (var part in parts)
{
    var partNode = graph.TryAdd(new Nodes.Part() { Name = part.Name });

    foreach (var device in part.Devices)
    {
        // Link part to device
        graph.Link(partNode, Node.Key(nameof(Nodes.Device), device), Edges.PartOf, Edges.HasPart);
    }
}

# Committing Changes

Pending operations are batched for performance. Ensure you commit them before finishing.

await graph.CommitPendingAsync();