AnDonger / dapper-dot-net

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

Can't Deserialize Enumeration when Field is "Status" #142

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have an MVC4 app with Dapper as my ORM. I created a class called Item, which 
has a field called Status:

public class Item {
  public StatusType Status { get; set; }
}

public enum StatusType : byte {
  NotStarted = 1, Started = 2, Finished = 3
}

When I create a new Item instance, and persist it, I can see it persisted in 
the database (column type is tinyint).

However, when I deserialize, the value is always zero. If I assign an 
enumeration to zero, it takes that value; otherwise, it just shows "0."

The fix for this, strangely, was to rename the field name in Item:

public StatusType StatusType { get; set; }

Everything then works. This is with the latest (1.13) from NuGet.

Original issue reported on code.google.com by alibhai....@gmail.com on 20 Jun 2013 at 5:22

GoogleCodeExporter commented 8 years ago
Wow. I have no reason to doubt what you say, but that is really odd. Definitely 
one for the next build!

Original comment by marc.gravell on 20 Jun 2013 at 5:35

GoogleCodeExporter commented 8 years ago
Yep, this one certainly drove me batty trying to figure it out. What helped me 
peg it down is that other enumerations deserialized fine on this class.

Original comment by alibhai....@gmail.com on 20 Jun 2013 at 6:08

GoogleCodeExporter commented 8 years ago
This is still a thing! I had a Status field which, once changed to 
SystemStatus, worked like a charm. That's a hum-dinger to track down...

Original comment by qerims@gmail.com on 16 Apr 2014 at 1:59

GoogleCodeExporter commented 8 years ago
This passes fine; cannot repro; I'm committing the test - can you help me repro 
at all?

        public void Issue142_Status()
        {
            var row1 = connection.Query<Item1>("select @Status as [Status]", new { Status = StatusType.Started }).Single();
            row1.Status.IsEqualTo(StatusType.Started);

            var row2 = connection.Query<Item2>("select @Status as [Status]", new { Status = Status.Started }).Single();
            row2.Status.IsEqualTo(Status.Started);
        }

Original comment by marc.gravell on 5 Aug 2014 at 3:56

GoogleCodeExporter commented 8 years ago
I can no longer repro this with Dapper 1.25 (albeit on a different project). 
Test cases:

- Database field is named "Status"
- Enum value is named "Status"
- Enum is enclosed in a class as a member variable named "Status"

Maybe the other person who reported this will have more luck, as their issue is 
only a couple of months recent (mine is from last year).

Original comment by alibhai....@gmail.com on 5 Aug 2014 at 4:21

GoogleCodeExporter commented 8 years ago
I'll go with that! If it's working for you there's no reason to believe it 
won't for me. 

Original comment by qerims@gmail.com on 6 Aug 2014 at 10:25

GoogleCodeExporter commented 8 years ago

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