RDF - Object Mapping for RDF in .net

MakoLab open-source component

Entity context factory

Create context factory

Next step is to create an entity context factory. Here we’ll show how it is done in code. This method is, much like the fluent mapping API, inspired by Fluent NHibernate. It is also possible to define the configuration in a app.config/web.config file. Please refer to the relevant this page.

We start off with a EntityContextFactory instance.

1
2
3
using RomanticWeb;

var contextFactory = new EntityContextFactory();

Add entity mappings

The MappingBuilder type contains a number of methods, with which it’s possible to add mappings from selected assemblies.

Here’s how to add all mappings from assembly of type IPerson.

1
2
3
4
contextFactory.WithMappings((MappingBuilder builder) =>
               {
                   builder.FromAssemblyOf<IPerson>();
               });

Configure an RDF storage

It is of course necessary to link our entity context factory to an actual RDF data backend. Currently there is a dotNetRDF backend. The example below shows how to use an in-memory triple store.

1
2
3
4
5
using RomanticWeb;
using RomanticWeb.DotNetRDF;

var dnrTripleStore = new VDS.RDF.TripleStore();
contextFactory.WithDotNetRDF(dnrTripleStore);

Configure a meta graph URI

As described on the concepts page, the RDF data accessed and modified by RomanticWeb is actually partitioned into Named Graphs and there is an additional Named Graph, which describes the former graphs.

Because there is no good default for that setting we decided that this must be always set up explicitly rather than using some fallback value. This way users must consciously shape their triple store.

1
contextFactory.WithMetaGraphUri(new Uri("http://example.com/data/"));