Linq to sql截断存储过程返回的字符串 [英] Linq to sql truncating string returned by Stored Procedure

查看:62
本文介绍了Linq to sql截断存储过程返回的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前曾问过这个问题.但是我没有得到任何答案.可能我不是很清楚.让我提供更多细节.

I have asked this question before. but i was not able to get any answer. may be i wasnt very clear. let me give some more details.

我有一个返回长字符串的SP.这是dbml文件代码

I have a SP which returns a long string. here is dbml file code

[Function(Name="dbo.spX")]
public ISingleResult<spXResult> spX([Parameter(DbType="VarChar(8000)")] string str)
{
    IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), str);
    return ((ISingleResult<spXResult>)(result.ReturnValue));
}

这是spXResult类

and here is spXResult class

public partial class spXResult
{
    private string _XML_F52E2B61_18A1_11d1_B105_00805F49916B;

    public spXResult()
    {  }

    [Column(Name="[XML_F52E2B61-18A1-11d1-B105-00805F49916B]", 
     Storage="_XML_F52E2B61_18A1_11d1_B105_00805F49916B", 
     DbType="NText", UpdateCheck=UpdateCheck.Never)]
    public string XML_F52E2B61_18A1_11d1_B105_00805F49916B
    {
        get
        {
            return this._XML_F52E2B61_18A1_11d1_B105_00805F49916B;
        }
        set
        {
            if ((this._XML_F52E2B61_18A1_11d1_B105_00805F49916B != value))
            {
                this._XML_F52E2B61_18A1_11d1_B105_00805F49916B = value;
            }
         }
     }
}

这是我的代码

ISingleResult<spXResult> result = ctx.spX("1234");

string returnStr = result.First().XML_F52E2B61_18A1_11d1_B105_00805F49916B;

一切都很好,当结果不是长字符串时,但是只要sp返回一个非常长的字符串,它就会截断结果.我不知道为什么.有人可以帮忙吗.

everything is fine, when the result is not a long string, but as soon as the sp returns a very long string, it truncates the result. i have no clue why.. can someone please help.

谢谢

推荐答案

LinqToSql将XML结果集拆分为多个块,因此您需要运行如下循环:

LinqToSql splits the XML result set into chunks, so you need to run a loop like this:

ISingleResult<spXResult> result = ctx.spX("1234");
string xml = "";
foreach (var x in result)
    xml += x.XML_F52E2B61_18A1_11d1_B105_00805F49916B;

或使用LINQ:

string xml = result.Aggregate("", (current, x) => current + x.XML_F52E2B61_18A1_11d1_B105_00805F49916B);

这篇关于Linq to sql截断存储过程返回的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆