使用LINQ在XML列字段上分组 [英] Group by on XML column field with LINQ

查看:72
本文介绍了使用LINQ在XML列字段上分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用LINQ对包含XML数据的on字段进行分组?

我正在获取XML数据类型无法进行比较或排序,除非使用IS NULL运算符.错误.

解决方案

不,这不可能-如果您无法比较等于/小于/大于的字段值,则无法对字段进行排序或分组操作.这不是LINQ to SQL的限制,它是SQL Server 2005不支持的限制.

如果尝试基于具有相同的文字XML值来对行进行重复数据删除,则可以添加一个新列,该列是XML列的副本,而不是转换为varchar的XML列,然后可以对该列的值进行分组. /p>

尽管如此,通常在XML上进行分组有点儿麻烦,如果可能的话,我会尝试使用替代的组密钥.

Is it possible to group by on field which contains XML data with LINQ?

I am getting The XML data type cannot be compared or sorted, except when using the IS NULL operator.error.

解决方案

No, it's not possible - you can't sort or group on a field if you can't compare the field values for equality / less than / greater than operations. This isn't a LINQ to SQL restriction, it's SQL Server 2005 that doesn't support this.

If you are trying to de-dupe rows based on having the same literal XML values, you could add a new column that is a copy of the XML column converted to varchar instead, then you can group on that column's value.

Generally though, grouping on XML is a bit of a smell and I would try to use a alternative group key if at all possible.

这篇关于使用LINQ在XML列字段上分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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