Dapper Deserializing XML

.net c# dapper orm serialization

Question

If I have XML stored in an nvarchar, does Dapper (or Dapper extensions) have a means to deserialize the XML into a DataContract type or a type with XmlRoot / XmlElement annotations?

If it does not handle it directly, is there an idiom for this? For example, perhaps my target DataContract class has a property that Dapper attempts to set, and that property performs the deserialization of the string?

Accepted Answer

No, currently it will not attempt to do anything special with this, except assign it to a string property that matches the column name. For now, I would suggest simply: separate the "get the data" and "deserialize the data into objects" steps. It is perhaps something that could be considered as an additional feature, but it isn't something that exists currently.


Popular Answer

I think Dapper has already supports XML data type as of v1.50.5 (or earlier version), it can convert XML data type to XmlDocument, XDocument or XElement.

It did convert XML data type to XElement in my code.



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