I have a bunch of stored procedures on SQL Server, each of which has an @res_xml xml output parameter. Each of these will return an XML fragment in @res_xml .
By βsnippetβ I mean that the XML snippet is incomplete and may contain several root nodes ( ConformanceLevel.Fragment ).
SQL Server has no problems with XML fragments, saves them just fine, and reuses them when one stored procedure wants to include the output of another stored procedure in its own output.
However, Linq2Sql does not support this. It would map the XML parameter to one XElement , and that would force the XML fragment.
I do not want to modify all stored procedures so that their output is always output to the root directory of the node. It would be a lot of typing, for this it would be necessary to explicitly throw away this dummy root node when reusing XML between stored procedures, and it would break existing non-linq2sql clients that support fragments perfectly. So this is linq that I am going to massage.
It is reported that XML parameters that may contain fragments are displayed instead of String . I'm fine with this, but is there a way to instruct the linq2sql XML map to String rather than XElement ?
I am currently doing the following:
- Drag procedures from the server explorer to the linq2sql constructor. The code is generated.
- Go to
DataClasses.designer and copy the generated code to call the procedures. - Paste this code in the
partial class DataClassesX . - Manually replace all
System.Xml.Linq.XElement with System.String . - Return to the designer and delete the drag and drop procedures.
It works, but annoying.
I cannot just replace in place, as this can be rewritten by the designer.
source share