实体框架调用 FOR XML 存储过程在 2033 个字符处截断

发布于 2024-09-08 18:15:30 字数 510 浏览 2 评论 0原文

我有一个存储过程,它在末尾使用 FOR XML 语句,并返回一些 XML。

我正在使用 .NET 4 和实体框架,当我执行此存储过程的函数导入并尝试通过实体框架调用它时,它会将返回值截断为 2033 个字符。

我将实体框架替换为传统的 ADO.NET 方法来调用存储过程,该存储过程也有同样的问题 - 在 2033 个字符处被截断 - 当我遇到以下 MSDN 文章时,解释了这是设计使然,并使用“ExecuteXMLReader” ”克服它的方法:

http://support.microsoft.com/kb/310378

所以这个现在正在作为临时修复,但我想使用实体框架函数导入,这样我就不会将 ADO.NET 代码与 EF 代码混合在一起。

有什么方法可以在 EF 中使用函数导入、返回 XML 并克服 2033 个字符的限制吗?

问候
BG264

I have a stored procedure which uses a FOR XML statement at the end of it, and returns me some XML.

I am using .NET 4 and the Entity Framework and when I do a function import of this stored procedure and try to call it through the Entity Framework it truncates the return at 2033 characters.

I swapped the Entity Framework for a traditional ADO.NET approach to call the stored procedure which had the same problem - truncated at 2033 characters - which is when I came across the following MSDN article explaining this is by-design and to use the "ExecuteXMLReader" method to overcome it:

http://support.microsoft.com/kb/310378

So this is working now as a temporary fix but I'd like to use Entity Framework function imports so I've not got ADO.NET code mixed up with EF code.

Is there some way I can use function imports in EF, return the XML and overcome the 2033 character limit?

Regards
bgs264

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪也成诗 2024-09-15 18:15:30

我今天遇到了同样的问题。

EF 函数调用以 2033 个字符长的字符串“块”返回 XML(例如,如果您的 XML 长度为 5000 个字符,您将收到 3 个结果:2033 个字符中的 2 个和 934 个字符中的 1 个)

您可以轻松附加这些块以返回完整的结果XML 列表。

I ran into the same issue today.

The EF function call returns the XML in 2033-long string 'chunks' (e.g. if your XML was 5000 chars long you would receive 3 results: 2 of 2033 chars and 1 of 934 chars)

You can easily append these chunks to return a full list of the XML.

苍暮颜 2024-09-15 18:15:30

我赞成费明的回答。对 Dementic(以及其他任何人)的回应,这里是一个代码片段。

从这:

using (var db = new MyEntities())
{
    IEnumerable<string> results = db.GetSomeXML(ProductCode);
    return results.FirstOrDefault();           
}

到这:

using System.Text;      //For the StringBuilder

using (var db = new MyEntities())
{
    StringBuilder retval = new StringBuilder();

    IEnumerable<string> results = db.GetSomeXML(ProductCode);
    foreach (var result in results)
        retval.Append(result);

    return retval.ToString();           
}

I upvoted Fermin's answer. Response to Dementic (and anyone else), here is a code fragment.

From this:

using (var db = new MyEntities())
{
    IEnumerable<string> results = db.GetSomeXML(ProductCode);
    return results.FirstOrDefault();           
}

To this:

using System.Text;      //For the StringBuilder

using (var db = new MyEntities())
{
    StringBuilder retval = new StringBuilder();

    IEnumerable<string> results = db.GetSomeXML(ProductCode);
    foreach (var result in results)
        retval.Append(result);

    return retval.ToString();           
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文