Dapper model mapping

.net c# dapper data-mapping

Question

I've been playing with Dapper and I have a question. Is there a way for me to be able to have an enumerator type property in my POCO class and use Dapper? Seems like every time I add a property which is of type Enumerator I get the following exception:

System.NotSupportedException: The type : *my_enum_type* is not supported by dapper

Am I missing something here? Is there an attribute that I can attach to these properties to specify which of them are mapping to database table columns?

Popular Answer

This is an old bug in dapper, ensure you use the latest version. Dapper used to perform no filtering on the input types properties.

Ok I figured this out and it was my fault for not seeing this in the 1st place. This is what I was doing initially:

Dim result = conn.Query("SELECT * FROM Users WHERE UserID = @UserID", New User With {.UserID = userID})

But what needed to be done is:

Dim result = conn.Query("SELECT * FROM Users WHERE UserID = @UserID", New With {.UserID = userID})

In other words declaring param as anonymous type is essential. If you declare param as a specific type and that type contains a property of type which is not covered by dapper code (such as Enum) then the code crashes with the above mentioned error. My User class had an Enum type property and it was causing the problem.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why