phnx47 / dapper-repositories

CRUD for Dapper
MIT License
659 stars 203 forks source link

Underscored names don't work with MatchNamesWithUnderscores = true #297

Closed b2soft closed 1 year ago

b2soft commented 1 year ago

Hello. I have a table auth with fields id and discord_id. I have such a model:

[Table("auth")]
public class AuthDataModel
{
    [Key, Identity]
    public int Id { get; set; }
    public string DiscordId { get; set; }
}

Dapper is configured to ignore underscores: Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;

Now when I try to get all the records using var foundUsers = (await m_authRepository.FindAllAsync()).ToList(); I get an error: 42703: column auth.discordid does not exist While this call works correctly: await m_authRepository.Connection.QueryAsync<AuthDataModel>("SELECT * FROM auth")).ToList(); May be related to https://github.com/DapperLib/Dapper/issues/818

What is the possible solution other than marking all the underscore named columns with [Column("underscored_name")] ?

Thanks

phnx47 commented 1 year ago

@b2soft SqlGenerator doesn't read Dapper.DefaultTypeMap.MatchNamesWithUnderscores. Current solution only with [Column("underscored_name")]

b2soft commented 1 year ago

Are there any plans to support such flag?

phnx47 commented 1 year ago

@b2soft Flag about mapping, not about sql generation... I guess you want support naming conventions in SqlGenerator. If you have time feel free to implement it and raise a PR.