在 Linq To SQL 中使用 XQuery? [英] Using XQuery in Linq To SQL?

查看:27
本文介绍了在 Linq To SQL 中使用 XQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

结果集只包含符合条件的记录,它从 XML 中提取一个值到一个名为值"的列中.很好很简单.

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.

Linq To SQL 能达到同样的效果吗?

Can the same thing be achieved with Linq To SQL?

我想让 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.

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

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

推荐答案

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

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

在 LINQ to SQL 中表示为字符串实体.您可以使用 XLINQ 来查询在 LINQ 中的 XML 列上SQL 实体 - 但这个查询会发生在你的中间层(在ASP.NET).你不能执行远程针对数据库和过滤器的 XQuery返回的结果基于首次发布.

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.

所以在回答你的问题时,我会说不".

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

这篇关于在 Linq To SQL 中使用 XQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆