Closed GoogleCodeExporter closed 9 years ago
forget to mention that the Db is MySql and dapper 1.6 return expected output
Original comment by anton.he...@gmail.com
on 23 Nov 2011 at 7:32
Update:
after few testing with console application and fresh mvc3 apps found that the
behavior of dapper enum mapping inconsistent when map the enum type directly.
mapping enum as property of class somehow consistently return correct map
public enum Role
{
Anonymous = 0, Authenticate = 1, Administrator = 2
}
public class User
{
public int Id { get; set; }
public Role Role { get; set; }
}
var user = Current.Db.Query<User>(@"SELECT roleId as Role, userId as Id
FROM users_roles
WHERE userId=@id", new { id = 2 }).FirstOrDefault();
the result of user.Role is somehow return expected output
Original comment by anton.he...@gmail.com
on 7 Dec 2011 at 6:21
The problem still exists in 1.8 and the latest source code too. Attached is a
patch file to the tests that adds an enum property to the multimap test to
prove it is broken.
Original comment by drew.fre...@gmail.com
on 19 Feb 2012 at 9:15
Attachments:
I can reproduce this as well in 1.8 from NuGet (using SQL Server 2008 R2). For
time being I just cast the value to the enum type:
var role = (Role) Current.DB.Query<int>("SELECT 1 as Role").First();
Original comment by kevin.e....@gmail.com
on 19 Mar 2012 at 4:10
This should now be fixed (recent code, not nuget)
Original comment by marc.gravell
on 6 Aug 2014 at 3:31
I can still reproduce it
public enum Premium : sbyte
{
None = -1,
Bronze = 1,
Silver,
Gold,
Platin
}
public class Test
{
public Premium Premium { get; set; }
}
var result = Current.DB.Query<Test>("select * from test").First();
Note: the value for premium in database is -1 (type: smallint(2), signed).
However the value in result will be Bronze (1).
Original comment by BoardT...@googlemail.com
on 11 Apr 2015 at 1:25
Original issue reported on code.google.com by
anton.he...@gmail.com
on 23 Nov 2011 at 7:26