Skip to content
Advertisement

Deserialize Postgres ARRAY [@tags] to List with Dapper?

I’m using Dapper with Npsql (Postgres). I’m saving a serialized list of strings to one column called tags:

which is resulting in {{first,second}} in the database.

My question is how to read it back to the model? Do I need some special SQL, or can I use SELECT id, text, tags FROM account;?

How can I dapper tell to deserialize it back to List<string>?

Thanks

Advertisement

Answer

The c# dapper code would look like the following (where notes & comments are a list of strings):

To let .NET, Dapper, and Postgres know how to handle the list of strings, create the following class.

Finally, add the following to your ConfigureServices() method within your Startup class

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement