本文介绍了dapper可以反序列化存储为文本的json吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);

我在数据库中存储了一个类似于json的字符串:[1,2,3,4,5]

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

当我使用Dapper查询数据库时,我希望dapper反序列化为对象MyType. Dapper希望MyArrayAsJson是一个字符串,因为它是,但是我希望它反序列化为一个int数组.这可能吗?

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?

推荐答案

Dapper不想使用任何花哨的序列化技巧:)基本上,没有:以字符串形式 then 从数据库读取它反序列化.

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

添加一个API,以BLOB/CLOB序列的形式提供对传入数据的更多直接/原始访问,这很好,但是今天在Dapper中并不存在.

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.

这篇关于dapper可以反序列化存储为文本的json吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:24