Skip to content

Primitives

Leonardo Porro edited this page Jan 25, 2023 · 15 revisions

A simple, plain schema with no members or elements, usually mapped to a single field of a database, and often represented by a .NET plain value such as string, int, bool.

The mapper copies primitives as-is without inspecting members or iterators. Target values are overwritten, there are no merge for primitives.

The list of built-in primitives can be found here.

Notice that any type can be configured as a primitive, even if it has members or items. eg.: string is an array of char, but for mapping purposes, we don't want to map it char by char but just copy the entire string value.

There are other custom or 3rd party types that may need to be treated as primitives, eg.: System.Data.Spatial.DbGeography, otherwise errors will occur as those types are not suitable to member by member mapping.

Configuration

In order to mark a type as primitive, add it to the Primitives list when configuring the library:

optionsBuilder.UseMapping(cfg =>
{
    cfg.Default(opts =>
    {
        opts.Primitives.Add(typeof(DbGeography));
     });
});