Dapper.Contrib Update ignores mapping

Created on 9 May 2016  路  7Comments  路  Source: StackExchange/Dapper

Hi,

some fields in my table have underscores like full_name so i did
DefaultTypeMap.MatchNamesWithUnderscores = true;
which works just fine when i retrieve entity with Get<> but throws "Invalid column name 'FullName'."
when i update

my model

public class SmUser{
        public int Id { get; set; } 
        public string Name { get; set; }    
        public string FullName { get; set; }   
        public string Email { get; set; }        
    }

Whet i run Get it works just fine, the property FullName is populated with data
var user = cn.Get<SmUser>(id);

but when i update the entity

user.Email = user.Email + "z";
cn.Update(user);

i get
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
"Invalid column name 'FullName'."

and the sql query
update smuser set [Name] = @Name, [FullName] = @FullName, [Email] = @Email where [Id] = @Id

"FullName" is the entity property, "full_name" is the db field
using dapper 1.42

v3.0

Most helpful comment

Is this really not addressed 4 years later?

All 7 comments

This feature is not supported . In Dapper.Contrib.SqlMapperExtensions.cs are fetched only the properties from the entity type and constructs directly the update statement.

DefaultTypeMap.MatchNamesWithUnderscores or any implementation of SqlMapper.ITypeMap is not taken in account.

I ll give it a try myself
Thanks

Same for Insert<>

Dapper: 1.50.0-rc2 and Dapper.Contrib: 1.50.0-beta8

I've created a pull request that implements the mapping for Insert and Update the last week, but I don't know if the maintainer have seen it yet.

Nice work! I'm happy to test it as soon as gets integrated.

Wow, I was really counting on this working. The db schema I'm using still has some old tables in it with underscored columns and the classes all utilize CamelCase property names. I went to test some updates and that didn't go so well.

Is this really not addressed 4 years later?

MatchNamesWithUnderscores = true still now working in insert case :(

Was this page helpful?
0 / 5 - 0 ratings