yuan8825399 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

MySql enum support #86

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a MySql table with a column of type int or tinyint
2. Create an object that has an enumerated property that maps to the int (or 
tinyint; my issue occurred with miniprofiler's MvcMiniProfiler.ProfileLevel 
Level Property)
3. Create a dapper query to map the table to the object (ie var result = 
connection.Query<MyObject>("select * from MyTable");

What is the expected output? What do you see instead?
An instance of MyObject populated by dapper.  Dapper is unable to map the int 
or tinyint column from MySql to the object's enumerated property, most likely 
do to a conversion issue.

What version of the product are you using? On what operating system?
Using MySql 5.5.18 on Windows 7.

Please provide any additional information below.

Link to the SO article where the problem is discussed: 
http://stackoverflow.com/q/8830123/435460

Original issue reported on code.google.com by jessebue...@gmail.com on 3 Mar 2012 at 9:25

GoogleCodeExporter commented 9 years ago
I think this issue may be related to a problem with getting enum values 
directly. For example, if you add the following unit test next to 
TestEnumStrings, you'll see the following exception: "0 should be equals to Bla"

        public void TestEnumValues()
        {
            connection.Query<TestEnum>("select 1").First().IsEqualTo(TestEnum.Bla);
            connection.Query<TestEnum>("select 'Bla'").First().IsEqualTo(TestEnum.Bla);
            connection.Query<TestEnum>("select 'BLA'").First().IsEqualTo(TestEnum.Bla);
        }

Original comment by gsl...@gmail.com on 30 Apr 2012 at 8:22

GoogleCodeExporter commented 9 years ago
simple workaround.. change tinyint to tinyint unsigned in mysql solves the 
problem
as the enum is byte type 

Original comment by anton.he...@gmail.com on 9 Oct 2012 at 6:00

GoogleCodeExporter commented 9 years ago
This should now work (code, not nuget)

Original comment by marc.gravell on 6 Aug 2014 at 3:40