None of the Entity Framework query languages ââ(LINQ to Entities and eSQL) directly support nested XML queries. Therefore, you cannot do this. Unless you run an XML query after calling AsEnumerable() , which, of course, is somewhat undesirable in terms of performance.
Having said that, you can probably write a Store function in SSDL that makes this filter for you.
Open the EDMX file in an XML editor and try adding an item in the StorageModel section (i.e. SSDL). <CommandText> (I think this is what it is called) of this Store function, where you can write the corresponding T-SQL, and you can also refer to the parameters of the function. Sorry, I do not have an example of this convenient.
Having done this, you can call the Store function in eSQL ie something like this:
SELECT VALUE treeNode FROM TreeNodes as treeNode WHERE StorageModelNamespace.MyXmlWrapperFunctionForNVarchar('(/edumatic/assessmentItem/@type)[1]', treeNode.Data) LIKE 'multiplechoice1'
In .NET 4.0, you can also write the stub function in .NET so that you can also call this function in LINQ:
i.e.
[EdmFunction("StorageModelNamespace", "MyXmlWrapperFunctionForNVarchar"] public static string MyXmlHelper(string path, string data) { throw new NotImplementedException("You can only call this function in a LINQ query"); }
then something like this:
var query = from e in edumatic3Context.TreeNodes where MyXmlHelper("(/edumatic/assessmentItem/@type)[1]", e.Data) .StartsWith("multiplechoice1") select e;
Please note that all of the above code is just a pseudo code that I haven't really tested, I'm just trying to help you get started.
Hope this helps
Alex
Entity Framework Team
Alex james
source share