假设我有一个包含 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/