开发者

Group by on XML column field with LINQ

开发者 https://www.devze.com 2022-12-18 00:31 出处:网络
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, i

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消