I find it very difficult to understand how to use an XML data column in SQL Server, especially for use with the Entity Framework.
In principle, one of our tables stores "user metadata" provided by users in XML form, so it was convenient to store this in the Xml column in the table.
However, one of the requirements of our application is to support metadata search. Users can provide an XPath query string, as well as a value, to compare the XPath value with, to search for items containing metadata matching their query.
I defined the XML xml functions as ideal for this (for example, [xmlcol] .exist ('/ path1 / path2 [0] [text () =' 'valuetest' '']), but they are not supported by the Entity Framework, annoyingly ( or, in particular, xml columns are not supported.) As an alternative, I tried to create a UDF that passes the user-provided XPath for xml functions, but then found that xml functions only allow string literals, so I cannot provide variables ...
At this moment, I did not have enough options.
I created a small piece of code that performs regular expression, replacing the result of IQueryable.ToString () to enable my XPath filter, and then send this line to the database manually, but there are problems with this too, for example, the result doesn’t seem to lazily loads navigation properties, for example.
SQLCLR SQLCLR, XPath. , , , SQL Server Azure SQLCLR - doh!
? , ...