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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.