在Linq To SQL中使用XQuery?

时间:2022-09-24 18:05:11

Let's say I have a table that has a column of XML type data. Within SQL, I can execute the following statement:

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

The result set contains only the records matching the criteria, and it extracts a value from the XML into a column called 'Value'. Nice and simple.

结果集仅包含与条件匹配的记录,并将XML中的值提取到名为“Value”的列中。很好,很简单。

Can the same thing be achieved with Linq To SQL?

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

I'd like to get SQL to do the heavy lifting and only return data matching my criteria rather than having to select, transfer, and then process a potentially massive chunk of data. As far as I can tell this isn't possible at the moment, but I thought I should ask.

我想让SQL做繁重的工作,只返回符合我标准的数据,而不必选择,传输,然后处理潜在的大量数据。据我所知,目前这是不可能的,但我想我应该问。

(The environment is .NET 3.5, VS2008, SQL Server 2005 if that helps)

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

1 个解决方案

#1


5  

I'm not exactly sure if this is out of date now, but according to Scott Guthrie XML datatypes are:

我现在还不确定这是否已经过时,但据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 to SQL实体中表示为字符串。您可以使用XLINQ查询LINQ to SQL权限中的XML列 - 但此查询将在您的中间层(在ASP.NET中)中进行。您无法对数据库执行远程XQuery,并根据第一个版本中的结果过滤返回的结果。

So in answer to your question, I'd say "no."

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

#1


5  

I'm not exactly sure if this is out of date now, but according to Scott Guthrie XML datatypes are:

我现在还不确定这是否已经过时,但据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 to SQL实体中表示为字符串。您可以使用XLINQ查询LINQ to SQL权限中的XML列 - 但此查询将在您的中间层(在ASP.NET中)中进行。您无法对数据库执行远程XQuery,并根据第一个版本中的结果过滤返回的结果。

So in answer to your question, I'd say "no."

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