Entity framework calling a FOR XML stored procedure truncates at 2033 characters

前端 未结 2 497
暗喜
暗喜 2020-12-17 19:44

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 functi

相关标签:
2条回答
  • 2020-12-17 20:24

    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();           
    }
    
    0 讨论(0)
  • 2020-12-17 20:30

    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.

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