Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

case sensitivity issue when mapping dynamic dapper objects #39

Open
iulian0512 opened this issue Jul 13, 2016 · 2 comments
Open

case sensitivity issue when mapping dynamic dapper objects #39

iulian0512 opened this issue Jul 13, 2016 · 2 comments

Comments

@iulian0512
Copy link

Dapper creates a case sensitive dictionary when returning the query result and you make a simple casing mistake on a column name the slapper will not map.
To fix change line 134 in Slapper.AutoMapper.cs with:
var dictionary = dynamicListOfProperties .Select(dynamicItem => new Dictionary<string, object>(dynamicItem as IDictionary<string, object>,StringComparer.OrdinalIgnoreCase)).ToList();

To reproduce the issue run this simple example:

    public class book
    {
        [AutoMapper.Id]
        public string name { get; set; }
    }

    static class Program
    {
        [STAThread]
        static void Main()
        {
            var cnn = DBUtils.CreateConnection("Data Source=localhost;Integrated Security=true;Initial Catalog=local;", DbServType.SqlServer);
            cnn.Open();

            var qres= cnn.Query<dynamic>(
                @"select 'xxxx' as 'Name'
                UNION
                select 'asdas' as 'Name'");

            var ent = AutoMapper.MapDynamic<book>(qres,false);

        }
    }
@nathan-alden-sr
Copy link

I wish SlapperAutoMapper had better support for controlling case sensitivity and conversions of one name to another. I am using a PostgreSQL database that has column names like my_column (the standard naming convention for PostgreSQL databases) and I'm trying to map them to a C# property called MyColumn. The only way I've found to do this is by aliasing every column that contains an underscore within the SQL statement. Tedious, for sure.

I also have similar problems mapping PostgreSQL enumeration values (my_enum_value) to a C# enumeration (EnumValues.MyEnumValue).

@Dolfik1
Copy link

Dolfik1 commented Feb 17, 2017

Also faced with this problem. Simple code to reproduce the problem:


    public class TestModel
    {
        [Slapper.AutoMapper.Id]
        public int IdModel { get; set; }

        public string Text { get; set; }
    }

...

    var dictionary = new List<Dictionary<string, object>>
    {
        new Dictionary<string, object>
        {
            { "IDMODEL", 1 },
            { "TEXT", "TEXT1" }
        },
        new Dictionary<string, object>
        {
            { "IDMODEL", 2 },
            { "TEXT", "TEXT2" }
        }
    };

    var items = Slapper.AutoMapper.Map<MaterialGeneric>(dictionary);
    Console.WriteLine(items.Count() == 2);

Output: False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants