tmsmith / Dapper-Extensions

Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance.
1.79k stars 585 forks source link

Custom mappers #308

Open jgwconsulting opened 2 years ago

jgwconsulting commented 2 years ago

I've been looking at creating a custom mapper but the example seems off to me (although it's probably me misunderstanding it!).

public class CustomPluralizedMapper<T> : PluralizedAutoClassMapper<T> where T : class 
{
    public override void Table(string tableName)
    {
        if(tableName.Equals("Person", StringComparison.CurrentCultureIgnoreCase))
        {
            TableName = "Persons";
        }

        base.Table(tableName);
    }
}

The code above appears to set TableName to "Persons" if the original table name is "Person" but it then calls base.Table passing the original tableName.

public virtual void Table(string tableName)
        {
            TableName = tableName;
        }

...which will set TableName back to "Person", won't it? I guess this will still work if the table name is always referenced from the overridden Table method, but it seems a bit odd.

valfrid-ly commented 2 years ago

Hi, I'll check this example but, just reading the code, it's seems wrong. tableName should be changed to Persons, not TableName

jgwconsulting commented 2 years ago

Ah cool, that's what I thought but I'm no stranger to getting things wrong, so I figured I'd check :) Thanks for all your hard work on this super handy project!