The data mapper in Griffin Framework now includes a fluent api

The data mapper in Griffin.Framework have been updated to support fluent mapping and some other new features.

Like in previous versions you do not need to do anything special in your mappings if the table matches the class. Just create an empty mapping class:

public class MyMapper : CrudEntityMapper<MyEntity>
{
	public MyMapper() : base("TableName")
	{
	}
}

It’s when you need to handle differences that you need to customize the mapping (and only for the specific property). Like other data mappers you can set which column name the property has or if the
property is the primary key (composite keys are supported).

However, with the fluent api you can also convert between column and property values. For instance if the property is an int and the column is a string.

public class MyMapper : CrudEntityMapper<MyEntity>
{
    public MyMapper()
        : base("TableName")
    {
        Property(x => x.Id)
            .ToColumnValue(propertyValue => propertyValue.ToString())
            .ToPropertyValue(colValue => int.Parse(colValue.ToString()));
    }
}

Another new feature is that you can ignore a property for CRUD operations or for SELECT statements (or both):

public class MyMapper : CrudEntityMapper<MyEntity>
{
    public MyMapper()
        : base("TableName")
    {
        // property is considered read only.
        Property(x => x.Name)
            .NotForCrud();
    }
}

Finally I’ve updated the SqlCommandBuilder so that it returns the SCOPE_IDENTITY() for inserts (and the mapper assigns the ID to the PK).

var user = new User("Jonas");
_uow.Insert(user);
Console.WriteLine(user.Id); //assigned.

The convention is that the a property named Id will automatically be assigned. If your primary key is named something else you can specify that in the mapping.