Semiodesk.Trinity.GraphDB 2.0.0-rc.2

This is a prerelease version of Semiodesk.Trinity.GraphDB.
dotnet add package Semiodesk.Trinity.GraphDB --version 2.0.0-rc.2
                    
NuGet\Install-Package Semiodesk.Trinity.GraphDB -Version 2.0.0-rc.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Semiodesk.Trinity.GraphDB" Version="2.0.0-rc.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Semiodesk.Trinity.GraphDB" Version="2.0.0-rc.2" />
                    
Directory.Packages.props
<PackageReference Include="Semiodesk.Trinity.GraphDB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Semiodesk.Trinity.GraphDB --version 2.0.0-rc.2
                    
#r "nuget: Semiodesk.Trinity.GraphDB, 2.0.0-rc.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Semiodesk.Trinity.GraphDB@2.0.0-rc.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Semiodesk.Trinity.GraphDB&version=2.0.0-rc.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Semiodesk.Trinity.GraphDB&version=2.0.0-rc.2&prerelease
                    
Install as a Cake Tool

Semiodesk.Trinity

CI NuGet License: MIT

An object mapper for RDF knowledge graphs in .NET.

Trinity maps RDFS/OWL vocabulary onto plain C# classes, so you work with objects and LINQ instead of hand-writing SPARQL and marshalling triples. It runs on top of dotNetRDF and talks to in-memory graphs, SPARQL endpoints, Virtuoso, GraphDB and Fuseki through one API.

Quick start

dotnet add package Semiodesk.Trinity --prerelease

Describe your domain as partial classes. The RDF terms are the mapping — there is no separate schema file, and no configuration:

using System;
using System.Collections.Generic;
using Semiodesk.Trinity;

[RdfClass("http://xmlns.com/foaf/0.1/Person")]
public partial class Person : Resource
{
    public Person(Uri uri) : base(uri) { }

    [RdfProperty("http://xmlns.com/foaf/0.1/name")]
    public partial string Name { get; set; }

    [RdfProperty("http://xmlns.com/foaf/0.1/age")]
    public partial int Age { get; set; }

    [RdfProperty("http://xmlns.com/foaf/0.1/knows")]
    public partial List<Person> Knows { get; set; }
}

Then read and write them like any other objects:

MappingDiscovery.RegisterAssembly(Assembly.GetExecutingAssembly());

var store = StoreFactory.CreateStore("provider=dotnetrdf");
var model = store.CreateModel(new Uri("http://example.org/contacts"));

var alice = model.CreateResource<Person>(new Uri("http://example.org/alice"));
alice.Name = "Alice";
alice.Age = 34;
alice.Commit();

var adults = from p in model.AsQueryable<Person>()
             where p.Age >= 18 && p.Name.StartsWith("A")
             orderby p.Name
             select p;

How the mapping works

A Roslyn source generator ships inside the package as an analyzer. For every partial member carrying [RdfProperty] it supplies the implementing half at compile time — the property mapping field, the getter and setter, and a GetTypes() override derived from [RdfClass]. Nothing runs after the build, so dotnet build is all you need on Windows, Linux and macOS.

It handles scalars, collections, language-invariant strings, resource references, multiple [RdfClass] attributes and inheritance. Only partial members are generated — and if you forget the keyword, or nest a mapped type, or leave out the Uri constructor, the generator says so at build time (TRIN001TRIN005) rather than leaving you with a mapping that quietly does nothing.

Mapped resources stay open: a Person can still carry predicates your class never declared, and ListValues() returns both the mapped and the unmapped ones. RDF is not forced into a closed schema.

Querying

LINQ queries are translated to SPARQL by Trinity's own query provider and executed on the store — nothing is fetched and filtered in memory. Where, OrderBy, Skip/Take, Any/All, Count, OfType, SelectMany, string and math operations, and navigation across linked resources are supported.

When you want the query language itself, it is right there — and registered vocabulary prefixes are already in scope:

var result = model.ExecuteQuery(new SparqlQuery(
    "SELECT ?s WHERE { ?s a foaf:Person ; foaf:name ?name . FILTER(CONTAINS(?name, 'A')) }"));

foreach (var person in result.GetResources<Person>()) { /* … */ }

Stores

Models are named graphs. A store hands them out, and a ModelGroup spans several while still behaving like a single model.

Store Package Connection string
In-memory / files Semiodesk.Trinity provider=dotnetrdf
SPARQL endpoint Semiodesk.Trinity provider=sparqlendpoint;endpoint=<uri>
Virtuoso Semiodesk.Trinity.Virtuoso provider=virtuoso;host=<host>;port=1111;uid=<user>;pw=<password>
GraphDB Semiodesk.Trinity.GraphDB provider=graphdb;host=<uri>;uid=<user>;pw=<password>;repository=<id>
Fuseki Semiodesk.Trinity.Fuseki provider=fuseki;host=<uri>;uid=<user>;pw=<password>;dataset=<name>

Backends are registered explicitly at startup:

StoreFactory.LoadProvider<VirtuosoStoreProvider>();

Graphs are read and written in the usual serializations — Turtle, TriG, N-Triples, N3, RDF/XML and JSON-LD — via store.Read(...)/store.Write(...), with store.LoadGraphs(...) as a thin helper for seeding schema or background graphs at startup.

The Fuseki backend is functional but currently affected by an upstream connector issue and should be considered experimental in this release.

Why RDF

  • A standard data model. RDF, RDFS, OWL and SPARQL are W3C standards with two decades of implementations behind them. Data and queries move between vendors.
  • SPARQL instead of a proprietary query language. Close enough to SQL to be familiar, and supported by every serious triple store.
  • Schema that is data. Ontologies are themselves RDF, stored alongside the data they describe, and can change while the application runs.
  • Inferencing where you want it. Class and property hierarchies, equality, transitivity — most RDF databases can answer queries over facts that were never explicitly stored.

Requirements

The libraries target netstandard2.0. Because mapped members are partial properties, consuming projects need a C# 13 compiler — .NET SDK 9.0 or later — with <LangVersion>13</LangVersion> or higher.

Documentation

Architecture Decision Records under doc/adr document the design and the reasoning behind it, including the mapping generator, the LINQ provider and the store model.

License

MIT — see LICENSE. Use it in commercial projects.

Originally created by Moritz Eberl and Sebastian Faubel at Semiodesk GmbH.

Contributing and support

Issues and pull requests are welcome at github.com/semiodesk/trinity-rdf. For contributions, please confirm you hold the rights to publish the code under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-rc.2 42 8/10/2026
2.0.0-rc.1 43 8/10/2026
1.0.3.77 3,091 2/17/2023