Dapper: throw error on failed match

Is there an option for dapper to throw an error if the Query method cannot find the property corresponding to the returned column in the result set? For example:

public class Person{
  public String FirstName {get; set;}
  public String LastName {get; set;}
}
...
conn.Query<Person>("select FName, LName from Users");

The above did not give an error, despite the fact that the data was not transferred due to a mismatch of the name.

If not, is there a reason not to add it? My old home micro-ORM did this, and I skipped this function, so I would have thought about trying to add it, but not if there were certain design decisions that already fixed it (ie, "raw performance") .

+4
source share
1 answer

A different naming property must be manual.

Dapper.FluentMap NuGet.

public class PersonMap : EntityMap<Person>
{
    public PersonMap()
    {
        // Map property 'FirstName' to column 'FName'.
        Map(p => p.FirstName)
            .ToColumn("FName");

        // Map property 'FirstName' to column 'FName'.
        Map(p => p.LastName)
            .ToColumn("LName");
    }
}

:

FluentMapper.Initialize(config =>
                       {
                           config.AddMap(new PersonMap());
                       });
-1

All Articles