views:

39

answers:

1

I have a XML column in a database and I'd like to query this XML using Linq(toSQL) in an efficient way.

MyTable.Select(e => e.XmlObject.Element("Phone").Value)

... Seems this queries the db for XmlObject but process Element("Phone") part outside the database? How do I create the query so that native SQL XML functions are used? (Do I want that?)

Updated: Would using a sproc be faster that the alternative used above?

+2  A: 

The LINQ to SQL provider does not support translating C# expressions to a SQL Server XQuery.

You are going to have to use plain old ADO.NET with a string-based query (either to a stored procedure or a parameterized command text query in code) to achieve the results you want.

Andrew Hare