I am storing primary key IDs as int in MS SQL Server. I want to convert them to HashIDs and store them as string in my entity objects. Also, I want to convert them back when storing my objects in the database. Is there a way to do so in Dapper? If not, any suggestions or workarounds?
Please, note that I am talking about a custom type handler only for a specific property of a specific entity type and not a generic custom type handler. Thank you.
I have successfully done so by use Dapper type handlers and converters. To do so, I have created a class called HashId which is converted to/from int when writing to/reading from database through Dapper. Then on my API (which is GraphQL), I used type custom types to convert them to strings before they reach the client.