views:

903

answers:

1

Let's say I have a table that has a column of XML type data. Within SQL, I can execute the following statement:

select   top 10  *,
         Content.value('(/root/item/value)[1]', 'float') as Value
from     xmltabletest
where    Content.value('(/root/item/MessageType)[1]', 'int') = 1

The result set contains only the records matching the criteria, and it extracts a value from the XML into a column called 'Value'. Nice and simple.

Can the same thing be achieved with Linq To SQL?

I'd like to get SQL to do the heavy lifting and only return data matching my criteria rather than having to select, transfer, and then process a potentially massive chunk of data. As far as I can tell this isn't possible at the moment, but I thought I should ask.

(The environment is .NET 3.5, VS2008, SQL Server 2005 if that helps)

+4  A: 

I'm not exactly sure if this is out of date now, but according to Scott Guthrie XML datatypes are:

represented as strings in LINQ to SQL Entities. You could use XLINQ to query on an XML column within your LINQ to SQL entitiy - but this querying would happen in your middle-tier (within ASP.NET). You can't execute a remote XQuery against the database and filter returned results based on that in the first release.

So in answer to your question, I'd say "no."

nlinus