[英]SQL Database with XML fields, select according to XElement using LINQ
I have a table in an SQL database, where the table configuration corresponds to 我在SQL数据库中有一个表,其中表配置对应于
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. 我想使用LINQ选择所有具有数据xml元素的行,其中包含config元素的值是...说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. 我非常确定Linq 2 SQL不支持您尝试执行的操作。 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?
您可能需要编写自定义SQL语句或使用用户定义的函数,如对此SO问题的解决方案中所讨论的: LINQ to SQL可以查询数据库服务器端的XML字段吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.