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

The Archive Base Latest Questions

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

There are a few questions on SO already regarding LINQ pivots and while a

  • 0

There are a few questions on SO already regarding LINQ pivots and while a couple of them outline my exact problem, I can’t successfully translate them to a working solution. I feel that this is mostly due to a join in my tables.

So for the benefit of all the LINQ junkies out there who love a problem, here’s another puzzle for you to work out. Please help me out (and earn some reputation points and much respect from me) by converting the following SQL stored proc script to LINQ:

ALTER PROCEDURE [dbo].[GetTimesheetForWeekById]     @timesheetid int,     @begindate VarChar(20),     @enddate VarChar(20) AS BEGIN      SELECT T.TaskName,         SUM(             case DATEPART(weekday, TE.StartTime)                 WHEN 1 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END             ) AS Sunday,         SUM(             case DATEPART(weekday, TE.StartTime)                 when 2 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END             ) AS Monday,         SUM(             case DATEPART(weekday, TE.StartTime)                 when 3 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END             ) AS Tuesday,         SUM(             case DATEPART(weekday, TE.StartTime)                 when 4 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END             ) AS Wednesday,         SUM(             case DATEPART(weekday, TE.StartTime)                 when 5 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END             ) AS Thursday,         SUM(             case DATEPART(weekday, TE.StartTime)                 when 6 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END             ) AS Friday,         SUM(             case DATEPART(weekday, TE.StartTime)                 when 6 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END             ) AS Saturday      FROM Tasks T     INNER JOIN TimeEntries TE on T.TaskID = TE.TaskID     WHERE TE.StartTime BETWEEN          (CONVERT(datetime, @begindate, 103)) AND (CONVERT(datetime, @enddate, 103))     AND TE.TimesheetID = @timesheetid     GROUP BY T.TaskName END 
  • 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:03:14+00:00Added an answer on May 10, 2026 at 10:03 pm

    Well, assuming that the foreign key has an object representation, something like:

            int timesheetId = ...         DateTime start = ..., end = ...         var qry = from timeEntry in ctx.TimeEntries               let date = timeEntry.StartTime.Date               where timeEntry.TimesheetId == timesheetId                 && date >= start                 && date <= end               group timeEntry by timeEntry.Task.TaskName into grp               select new {                   TaskName = grp.Key,                   Monday = grp.Where(x => x.StartTime.DayOfWeek == DayOfWeek.Monday).Count(),                   Tuesday = grp.Where(x => x.StartTime.DayOfWeek == DayOfWeek.Tuesday).Count(),                   Wednesday = grp.Where(x => x.StartTime.DayOfWeek == DayOfWeek.Wednesday).Count(),                   Thursday = grp.Where(x => x.StartTime.DayOfWeek == DayOfWeek.Thursday).Count(),                   Friday = grp.Where(x => x.StartTime.DayOfWeek == DayOfWeek.Friday).Count()               }; 

    Unfortunately, some of the specifics depend on the SQL provider – i.e. which functions (like DayOfWeek etc) it can map successfully as TSQL. Let me know if you get problems…

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

Sidebar

Related Questions

I know there are a few questions on stack already regarding this, and I
I know there are already a few questions regarding recommendations for C++ unit test
I know there are already a few questions like this but I can't seem
While there is quite a few questions about copy constructors/assignment operators on SO already,
I realise there are a fair few questions on here already with regard to
I know there are quite a few questions on this already and i've looked
There are a few questions about configuring Apache for local development, such as this
A few questions on MS Access databases - Size: Are there limits to the
I realize there are a few other questions about why Cygwin is apparently slow,
I know that there are a few similar questions and I googled a lot

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.