Home » .NET » The data mapper in Griffin Framework now includes a fluent api

About Jonas Gauffin

Jonas Gauffin

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.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a sysadmin Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. Introduction to NGINX
2. Apache HTTP Server Cookbook
3. VirtualBox Essentials
4. Nagios Monitoring Cookbook
5. Linux BASH Programming Cookbook
6. Postgresql Database Tutorial
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments