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 91167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:59:15+00:00 2026-05-10T22:59:15+00:00

I have the following Linq to SQL query, in which I’m trying to do

  • 0

I have the following Linq to SQL query, in which I’m trying to do a multi-column GROUP BY:

return from revision in dataContext.Revisions        where revision.BranchID == sourceBranch.BranchID-1                 && !revision.HasBeenMerged        group revision by new Task(revision.TaskSourceCode.ToUpper(),                                    revision.TaskSourceID)        into grouping        orderby grouping.Key ascending        select (ITask)grouping.Key; 

This throws InvalidOperationException (‘Cannot order by type ‘Task’.’).

Is there an interface that Task must implement (it already implements IComparable, IComparable<ITask>)? Does Task need to be a Linq to SQL Entity (it isn’t, currently, since there’s no corresponding table). Or is this just something that Linq to SQL doesn’t support?

Note that I’ve already tried an anonymous type for the grouping, which failed with a similar InvalidOperationException:

... group revision by new { Code = revision.TaskSourceCode.ToUpper(),                         Id = revision.TaskSourceID }  ... 

For what it’s worth, note that the Task object is a composite of 2 fields; one is a single character (typically ‘S’ or ‘B’) and the other is an int (actually a cross-database ‘foreign key’ if you like). The act of ordering by Tasks just compares their string representations; E.G. Task ‘B101’ < Task ‘S999’

  • 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. 2026-05-10T22:59:15+00:00Added an answer on May 10, 2026 at 10:59 pm

    Looks like you already have your solution, but just FYI LINQ to SQL does support .ToUpper().

    For instance:

    NorthwindDataContext dc = new NorthwindDataContext(); Product product = dc.Products.Single(p => p.ProductName.ToUpper() == 'CHAI'); 

    Is translated into:

    exec sp_executesql N'SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], [t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued] FROM [dbo].[Products] AS [t0] WHERE <b>UPPER([t0].[ProductName]) = @p0</b>',N'@p0 nvarchar(4)',@p0=N'CHAI' 

    Hope that helps.

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

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I have the following Linq to SQL query, in which I'm trying to do
I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr) from tpoll_answer
I'm having trouble getting LINQ to translate something into the query I need. In
I have the following code in my controller: public ActionResult Details(int id) { var
I know there have been numerous questions here about inline sql vs stored procedures...

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.