Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6577369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:37:36+00:00 2026-05-25T15:37:36+00:00

In my code I have the following Linq Query: IQueryable<Data> charts = (from report

  • 0

In my code I have the following Linq Query:

IQueryable<Data> charts = (from report in ctx.Charts group report by new 
    { 
        Name = report.ChartTitle.ChartType.ChartCategory.CategoryName,
        id = report.ChartTitle.ChartType.ChartCategory.ChartCategoryId, 
        Period = report.Period 
    } into d
    select new Data
    {
        Name = d.Key.Name,
        Id = d.Key.id,
        Period = d.Key.Period,            
        Reports = from r in d group r by new 
        { Title = r.ChartTitle.Name, id = r.ChartTitle.ChartTitleId } into rs
        select new Report
        {
            Title = rs.Key.Title,
            Id = rs.Key.id,
            Charts = (from c in rs group c by new 
                    { 
                        ChartId = c.ChartId, 
                        FiscalYear = c.FiscalYear, 
                        ModifiedDate = c.ChartView.ModifiedDate, 
                        Function = c.Function.DisplayName, 
                        ChartData=c.ChartView.ViewData
                    } into cs
                    select new ChartInfo 
                    { 
                        ChartId = cs.Key.ChartId, 
                        FiscalYear = cs.Key.FiscalYear,
                        ModifiedDate = cs.Key.ModifiedDate, 
                        Function = cs.Key.Function, 
                        ChartData=cs.Key.ChartData 
                    })
    }});

In the above code if I exclude the “ChartData” field (which is of XML datatype), the query executes fine. But when ever I include this field it throws the following error :”The xml data type cannot be selected as DISTINCT because it is not comparable.”

Let me know what I am missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:37:36+00:00Added an answer on May 25, 2026 at 3:37 pm

    You can’t group by XML types. This is a SQL restriction, not a LINQ-to-SQL retriction. (See Group by on XML column field with LINQ and select an xml type column in select query with group by SQL Server 2008)

    Do you need to group by the XML column? The alternative would be to group by your other columns and then select the first XML value as a result.

    Charts = (from c in rs group c by new  
    {
        ChartId = c.ChartId,
        FiscalYear = c.FiscalYear,
        ModifiedDate = c.ChartView.ModifiedDate,
        Function = c.Function.DisplayName,
    } into cs                     
    select new ChartInfo
    {
        ChartId = cs.Key.ChartId,
        FiscalYear = cs.Key.FiscalYear,
        ModifiedDate = cs.Key.ModifiedDate,
        Function = cs.Key.Function,
        ChartData=cs.Value.FirstOrDefault().ChartData
    }) 
    

    When using LINQ-to-SQL the items being grouped are still accessible – you don’t need to include every ‘selected’ property / column in the group by` clause like you would in SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have following code with LINQ var q = (from web in DataContext.Webs select
I have the following LINQ code: var posts = (from p in db.Posts .Include(Site)
I have the following LINQ to Entities query... var results = from c in
Hello I have the following code to retrieve data from my db using nhibernate
I've got the following code: Dim query As IQueryable(Of someObject) = New ObjectQuery(Of someObject)(queryString,
I have the following linq query: var file = (from p in database.tblFile join
I have a following LINQ-to-entities query IQueryable<History<T>> GetFirstOperationsForEveryId<T> (IQueryable<History<T>> ItemHistory) { var q =
I have the following LINQ query in an application. The data source is a
I have the following code using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace
I have following code for loading image from url in xml parsing endElement method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.