Dapper version 1.12.0.0 XML parameter no longer working

c# dapper

Question

When passing an xml string through dapper to SQL Server 2008, dapper seems to be creating a parameter for each one of characters in the xml string.

For example, if the string is <outer></outer> it appears to be creating a parameter for each character ( '<', 'o', 'u', 't', etc..)

In old version the code would pass one parameter (namely the xml parameter that was specified) into the stored procedure.

Set up code looks like the following -

var xml = @"
<OuterElement>
  <InnerElement>1</InnerElement>
  <InnerElement>2</InnerElement>
  <InnerElement>3</InnerElement>
  <InnerElement>4</InnerElement>
</OuterElement>";

var parameters = new Dapper.DynamicParameters();
parameters.Add("@XmlParameter", xml, DbType.Xml); 
SqlMapper.Query(
  connection, 
  "dbo.TestXmlInput", 
  parameters, 
  commandType: CommandType.StoredProcedure, 
  commandTimeout: 60
);

My questions are as follows: Can anyone else reproduce this? If so, Was this change intentional or a bug? Is there a workaround for achieving xml parameter passing?

The generated SQL looks like this:

exec dbo.TestXmlInput (@XmlParameter1, @XmlParameter2, @XmlParameter3, ...)

Any help would be greatly appreciated.

Accepted Answer

Historically, DbType.Xml had been internally hijacked to represent something different. This is being problematic. Basically, when I made parameter expansion (where Id in @ids) work in DynamicParameters, it broke xml.

I have now created a different way of representing this, and pushed the updated source to google-code and github. If you use the updated code, it should work fine. I haven't deployed NuGet yet - let me know if you need this.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why