0

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

Chau
  • 5,540
  • 9
  • 65
  • 95
  • possible duplicate of [Can LINQ to SQL query an XML field DB-serverside?](http://stackoverflow.com/questions/282391/can-linq-to-sql-query-an-xml-field-db-serverside) – podiluska Jun 03 '14 at 10:44

1 Answers1

1

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: Can LINQ to SQL query an XML field DB-serverside?

Community
  • 1
  • 1
Egil Hansen
  • 15,028
  • 8
  • 37
  • 54