Using Dapper to return XML string from T-SQL stored procedures

后端 未结 1 1688
粉色の甜心
粉色の甜心 2021-01-05 20:13

I am working on a project to convert a large VB6 application to .NET. I decided to create a project to provide a facade to the existing VB6 ADO code, where I am using the am

相关标签:
1条回答
  • 2021-01-05 20:23

    After testing, I see that Dapper does indeed support pulling the XML from stored procedures.

    var result = conn.Query<string>(@"select * from <someTable> for xml auto");
    

    This will return an array of string with each element containing up to 2,033 characters, which you can simple join to have your result as a single string.

    var fullResult = string.Join("", result);
    

    or

    var fullResult = string.Concat(result);
    

    or, all in one step:

    var result = string.Concat(conn.Query<string>(
        @"select * from <someTable> for xml auto", buffered: false));
    

    So, there is no need for me to implement ExcuteXmlReader method myself, and now I can let Dapper handle the parameters normally.

    0 讨论(0)
提交回复
热议问题