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

查看:69
本文介绍了在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)

推荐答案

我不确定现在是否已经过时,但是根据

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天全站免登陆