views:

84

answers:

1

I have a table in an SQL database, where the table configuration corresponds to

ID
Name string
data xml

where the datafield might (but not necessarily) contain a descendant element

<config>Some value...</config>

Using LINQ I want to select all the rows that has a data xml element which contains the config element with a value of... say 17.

My approach has been something like:

var query = from x in db
            from y in x.data.descendants("config")
            where y.Value == "17"
            select x;

But this throws an exception about the Value not being valid.

How should I formulate this query?

Regards, Casper

+1  A: 

I am pretty sure that Linq 2 SQL does not support what you are trying to do. You would probably need to write a custom SQL statement or use a user defined function as discussed in the solution to this SO question: http://stackoverflow.com/questions/282391/can-linq-to-sql-query-an-xml-field-db-serverside

Egil Hansen