linq - 在 Linq To SQL 中使用 XQuery?

标签 linq sql-server-2005 linq-to-sql xquery

假设我有一个包含 XML 类型数据列的表。在 SQL 中,我可以执行以下语句:

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

结果集仅包含与条件匹配的记录,并从 XML 中提取一个值到名为“值”的列中。好看又简单。

使用 Linq To SQL 可以实现同样的事情吗?

我想让 SQL 完成繁重的工作,只返回符合我的条件的数据,而不必选择、传输和处理潜在的大量数据。据我所知,目前这是不可能的,但我想我应该问一下。

(如果有帮助,环境是 .NET 3.5、VS2008、SQL Server 2005)

最佳答案

我不确定现在这是否已经过时,但根据 Scott Guthrie XML 数据类型是:

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.



所以在回答你的问题时,我会说“不”。

关于linq - 在 Linq To SQL 中使用 XQuery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/214060/

相关文章:

c# - 在 C# 中使用 linq 计算 IEnumerable 中项目的出现次数

sql - 如何将使用公用表表达式的 SQL 查询转换为不使用公用表表达式的查询(适用于 SQL Server 2000)

c# - 像 LINQ to SQL 那样将英语单词复数化

c# - SQLITE : Return 5 most recent records today and format date/time

c# - LINQ 等效于 List<T>.Find()?

c# - max 和 group by 问题与 LINQ

wpf - Linq查询非常慢

sql-server-2005 - 生成索引在两个数字之间的行

sql-server - SQL Server 2005 使用表达式进行 Order BY

c# - 使用 partial 从自动生成的 linq-sql 对象中抽象方法