brucezhang80 / dapper-dot-net

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

Enum support in parameters #32

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Are there any plans to support enums?

If not, some kind of mapping override as suggested by Matt 
(http://code.google.com/p/dapper-dot-net/issues/detail?id=24) would be useful. 
This way we could cast to the enums ourselves.

Original issue reported on code.google.com by b...@planetcloud.co.uk on 3 Jun 2011 at 3:58

GoogleCodeExporter commented 9 years ago
It has full support for enums, either as the raw int/byte/etc, or incoming as 
strings.

The only caveat: your db data and the enum underlying type must agree (I.e. a 
tinyint in the db maps to a byte enum).

Is there a specific case that isn't working?

Original comment by marc.gravell on 3 Jun 2011 at 6:18

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 3 Jun 2011 at 6:19

GoogleCodeExporter commented 9 years ago
After reading your comment I had a look and it seems that the enums were being 
stored as string (fluent nhibernate generated). I therefore created a new 
convention to make sure these were mapped as int.

My enum is:

    public enum SiteState
    {
        Disabled = 0,
        Enabled = 1
    }

And this is now correctly stored as an int in my database.

However, I now get the following error:

Conversion failed when converting the nvarchar value 'Enabled' to data type 
int. 

Any ideas?

Original comment by b...@planetcloud.co.uk on 3 Jun 2011 at 7:37

GoogleCodeExporter commented 9 years ago
Ignore that last one I had a problem with my parameters. I am noticing that I 
need to explicitly cast my parameters as int:

new { state = (int)SiteState.Enabled, urlstate = (int)UrlMappingStatus.Active 
});

Is this expected?

Original comment by b...@planetcloud.co.uk on 3 Jun 2011 at 7:44

GoogleCodeExporter commented 9 years ago
No, that sounds like a bug with the parameter handling not considering the 
underlying type correctly. I will fix that.

Original comment by marc.gravell on 3 Jun 2011 at 8:54

GoogleCodeExporter commented 9 years ago
fixed

Original comment by marc.gravell on 5 Jun 2011 at 10:12

GoogleCodeExporter commented 9 years ago
Hi Marc,

I'm having a similar issue with nullable enums. Unless I cast them as (int?) 
when setting the dynamic params it fails with an Type not supported exception.

Chris

Original comment by christop...@gmail.com on 11 Jun 2011 at 9:34

GoogleCodeExporter commented 9 years ago
@Chris - a: do you have repro code / example, and b: what version?

Original comment by marc.gravell on 11 Jun 2011 at 9:52

GoogleCodeExporter commented 9 years ago
@Marc, sorry for wasting your time. I thought I had the latest version as I 
only downloaded it on Friday, however I got it from the GitHub clone which 
didn't have this fix in it. I just grabbed the latest version from here and its 
working.

Thanks for the great object mapper!

Original comment by christop...@gmail.com on 13 Jun 2011 at 9:45

GoogleCodeExporter commented 9 years ago
No problem - thanks for the update

Original comment by marc.gravell on 13 Jun 2011 at 10:12