Can dapper deserialize json stored as text?

不问归期 提交于 2019-12-13 00:16:06

问题


public class MyType
{
    public int Id { get; set;}
    public int[] MyArray { get; set; }
}

var sql = "SELECT id, MyArrayAsJson as MyArray";
var x = await connection.QueryAsync<MyType>(sql);

I have a string stored in the database which looks like json: [1,2,3,4,5]

When I query the db with Dapper, I would like dapper to deserialize to an object, MyType. Dapper wants MyArrayAsJson to be a string because it is, but I want it to deserialize to an int array. Is this possible?


回答1:


Dapper wants nothing to do with your fancy serialization shenanigans :) Basically, no: read it from the database as a string, then deserialize.

Adding an API that provided more direct / raw access to the incoming data as a BLOB/CLOB sequence would be nice, but it doesn't exist in Dapper today.



来源:https://stackoverflow.com/questions/49888334/can-dapper-deserialize-json-stored-as-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!