问题
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
回答1:
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.
回答2:
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();
}
来源:https://stackoverflow.com/questions/3228303/entity-framework-calling-a-for-xml-stored-procedure-truncates-at-2033-characters