Group by on XML column field with LINQ
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.
精彩评论