You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
case sensitivity issue when mapping dynamic dapper objects #39
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);
}
}
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).
Reacted by iulian0512, Nikolay M, Tuan Hoang Anh and Gustav Kyllenbeck
Activity
nathan-alden-sr commentedon Aug 11, 2016
I wish
SlapperAutoMapperhad better support for controlling case sensitivity and conversions of one name to another. I am using a PostgreSQL database that has column names likemy_column(the standard naming convention for PostgreSQL databases) and I'm trying to map them to a C# property calledMyColumn. 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 commentedon Feb 17, 2017
Also faced with this problem. Simple code to reproduce the problem:
Output: False