As noted in the previous chapter, Elementary automatically validates your mappings:
Performs validation (Most are optional in Xml mappings and automatic with attribute mappings)
Checks the defined database connections and makes sure they work
(Xml only) Compares the defined database mappings to the actual schema
(Xml only) Compares the defined classes and properties and compares them to the actual assembly
Validates the class mappings to the database schema
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.