Our development has come across a major roadblock in terms of Linq to Sql and Sql 2005+ Xml Fields. We have an xml blob field containing fields ...
<Profile name-first="Terry" name-last="Aney" [...more]/>
To use LINQ to SQL, we created UDF in SQL and added it to our DataContext and named it (based on LINQ to SQL (Part 6 - Retrieving data using stored procedures) ). However, when we use these functions, indexing XML by SQL seems futile. Filtered and ordered query with a population of 14,000 rows, and it expires with a 30 second CommandTimeout by default. But if we take the command text (sniffed by SQL Profiler) and replace the UDF with direct XQuery, the query will take less than a second (obviously what we want). I saw similar questions about Xml Fields (i.e. this question ), but the general answer is to use UDF, but we have proven that they are ineffective if you use them extensively.
We hope that there is some low-level point where we can capture command text and change the UDF to the appropriate XQuery syntax (via RegEx). Not perfect, but this is the only solution that we see practically possible. We are open to anything - command translation of text, CLR integration with SQL, etc.
In certain situations, we could do this already. For example, if we always have IQueryable, where T is not an anonymous and / or complex / nested type, we could call GetCommandText and then call DataContext.Translate (). However, for anonymous / complex types and / or scalar queries, we do not see a place to connect.
Any suggestions are welcome.
Terry source share