假设我有一个表,它有一列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中提取为名为“Value”的列.尼斯和简单
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.
所以在回答你的问题时,我会说“不”.