开发者

SQL Database with XML fields, select according to XElement using LINQ

I have a table in an SQL da开发者_运维技巧tabase, 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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜