Skip to content

Property Metadata

By default, Gremlinq derives every property's database key from the C# property name and every element's label from the class name. Property Metadata configuration lets you override these defaults — renaming individual properties, applying naming conventions across the whole model, and controlling which properties are written to the graph when adding or updating elements.

All configuration is applied inside ConfigureModel, which is available on IGremlinQueryEnvironment via ConfigureEnvironment.

Serialization Behaviour

These options control whether a property is included when Gremlinq issues an AddV/AddE (add) or UpdateV/UpdateE (update) command. They are configured per element type using ConfigureElement<TElement>.

IgnoreOnUpdate — skip a property when updating

Marks a property so that it is never written during an update operation. This is the most common pattern for Id — you want the id to be read back from the graph, but you do not want to overwrite it on every save.

C#
var source = g
    .UseGremlinServer<Vertex, Edge>(_ => _.AtLocalhost())
    .ConfigureEnvironment(env => env
        .UseNewtonsoftJson()
        .ConfigureModel(model => model
            .ConfigureVertices(vertices => vertices
                .ConfigureElement<Person>(config => config
                    .IgnoreOnUpdate(p => p.Id)))));
IgnoreOnAdd — skip a property when adding

Marks a property so that it is not sent when a new element is first created. Useful when the database assigns the value automatically (e.g. a server-generated timestamp).

C#
var source = g
    .UseGremlinServer<Vertex, Edge>(_ => _.AtLocalhost())
    .ConfigureEnvironment(env => env
        .UseNewtonsoftJson()
        .ConfigureModel(model => model
            .ConfigureVertices(vertices => vertices
                .ConfigureElement<Person>(config => config
                    .IgnoreOnAdd(p => p.Name)))));
IgnoreAlways — never serialize a property

Marks a property so that it is excluded from both add and update operations. The property can still be populated from data returned by the graph; it simply will not be written.

C#
var source = g
    .UseGremlinServer<Vertex, Edge>(_ => _.AtLocalhost())
    .ConfigureEnvironment(env => env
        .UseNewtonsoftJson()
        .ConfigureModel(model => model
            .ConfigureVertices(vertices => vertices
                .ConfigureElement<Person>(config => config
                    .IgnoreAlways(p => p.Name)))));

Property Naming

By default the C# property name is used as the database key. You can override this either individually or in bulk.

ConfigureName — rename a single property

Maps one C# property to an explicit database key. In the example below, Person.Name will be stored and queried under the key "person_name" in the graph.

C#
var source = g
    .UseGremlinServer<Vertex, Edge>(_ => _.AtLocalhost())
    .ConfigureEnvironment(env => env
        .UseNewtonsoftJson()
        .ConfigureModel(model => model
            .ConfigureVertices(vertices => vertices
                .ConfigureElement<Person>(config => config
                    .ConfigureName(p => p.Name, "person_name")))));
UseCamelCaseMemberNames — camelCase convention for all properties

Applies camelCase formatting to every property name in the model (both vertices and edges). For example, a C# property FirstName becomes "firstName" in the database.

C#
var source = g
    .UseGremlinServer<Vertex, Edge>(_ => _.AtLocalhost())
    .ConfigureEnvironment(env => env
        .UseNewtonsoftJson()
        .ConfigureModel(model => model
            .ConfigureElements(elements => elements
                .UseCamelCaseMemberNames())));

To restrict the convention to vertices or edges only, replace ConfigureElements with ConfigureVertices or ConfigureEdges respectively.

Label Conventions

Element labels identify the type of a vertex or edge in the graph. By default the C# class name is used verbatim. You can override the label for every type at once using a naming convention.

UseCamelCaseLabels — camelCase labels for vertices

Converts every vertex class name to camelCase when used as a graph label. For example, a class named PersonAccount gets the label "personAccount".

C#
var source = g
    .UseGremlinServer<Vertex, Edge>(_ => _.AtLocalhost())
    .ConfigureEnvironment(env => env
        .UseNewtonsoftJson()
        .ConfigureModel(model => model
            .ConfigureVertices(vertices => vertices
                .UseCamelCaseLabels())));

Replace ConfigureVertices with ConfigureEdges to apply the same convention to edge labels, or use ConfigureElements to apply it to both at once.

A lowercase variant is also available: UseLowerCaseLabels converts every label to its fully lowercase form (e.g. PersonAccount"personaccount").


Related: Graph Model — label scanning, type hierarchies, and assembly registration.