Skip to content

AllowNulls and DefaultValue

Cleve Littlefield edited this page Feb 1, 2016 · 1 revision

By default, Mata will check for null on any property type that supports null, such as string and Nullable<?>.

You can set the AllowNulls property to false if you know a column will never return null, saving the null check and speeding things up a bit.

var mapDefinition = new MapDefinition<FooModel>();
mapDefinition.Map(model => model.Name, allowNulls: false);

If you want to convert null values to some sort of default, you can do that too (allowNulls must be set to true to set default value):

var mapDefinition = new MapDefinition<FooModel>();
mapDefinition.Map(model => model.Name, allowNulls: true, defaultValue: string.Empty);
Clone this wiki locally