Chapter 11. Mapping Validation - Reflection and Schema Checking

As noted in the previous chapter, Elementary automatically validates your mappings:

This is especially useful when using Xml mappings, since it ensures typos, etc. are caught. To see an example of how this works, let's revisit our Category class and modify it. Here's the original, correct version:

using System;
using Adapdev.Text;
using Elementary.Attributes;

namespace Elementary.Northwind.Samples.Attributes.ChildMappingOneToNGenericInferred
{
    [ElementaryClass]
	public class Category
	{
        [Persist(Column="categoryid")]
		public int Id;
        [Persist(Column="categoryname")]
        public string Name;
        [Persist]
        public string Description;
        [Persist]
        public byte[] Picture;

		public override string ToString() 
		{
			return StringUtil.ToString(this);
		}
	}
}

Now, let's modify it by taking out the categoryname information on the Name property. Elementary will look for a column named "Name" instead of "categoryname" now:

using System;
using Adapdev.Text;
using Elementary.Attributes;

namespace Elementary.Northwind.Samples.Attributes.ChildMappingOneToNGenericInferred
{
    [ElementaryClass]
	public class Category
	{
        [Persist(Column="categoryid")]
		public int Id;
        [Persist]
        public string Name;
        [Persist]
        public string Description;
        [Persist]
        public byte[] Picture;

		public override string ToString() 
		{
			return StringUtil.ToString(this);
		}
	}
}

When Elementary loads, it'll catch this and note it in the LoadLog:

...
Validating references...
	Checking database references...
		Checking database native connection...
		Checking database OLEDB connection...
		Checking database schema...
		Checking class to table mappings...
			[Elementary.Northwind.Samples.Attributes.ChildMappingOneToNGenericInferred.Category] 
			column name not found for property Name
Done.