Dapper – JSON type custom mapper

Let’s assume that we have such read model:

And we want store Category and FieldValues in the table, as JSON string.  How to handle JSON serialization and deserialization in Dapper? TypeHandlers TypeHandlers are an option in Dapper to serialize / deserialize objects during saving and querying the database. First, we define an implementation of ITypeHandler interface:

SetValue method… Continue reading

Dapper – many to many relation in a single request

During my CQRS journey, I implemented many-to-many data querying, in the single database request. I achieved getting all products with associated entities at the same time. To achieve the same, we need to define a temporary table to store all first-level entities:

Then insert first-level entities into this table:

With such temporary table, we are able… Continue reading