Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 484
bgs264 Avatar asked Jul 12 '10 12:07

bgs264


1 Answers

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.

like image 70
Fermin Avatar answered Sep 21 '22 00:09

Fermin