I’m using dapper and am having issues with casting a string value from the db to an int. Has anyone overriden the TypeMap to allow for this?
Any suggestions would be great.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Dapper is picky about the types it maps. This protects you from all sorts of nasty errors that pop up later.
For example, your db could return:
010hello10a10374837483748374837483748374834784378437438743874384738473There is no clear course of action for mapping this kind of stuff to an
Int32That said, there are two strategies you can follow with dapper that do not require changes to IL generation.
Option 1: Shadow property
Option 2, cast in SQL
There is no clean way to extend the mapping functionality in Dapper, if you do so you will be stuck needing to merge any fixes we add over time to your local copy.