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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:17:23+00:00 2026-05-17T15:17:23+00:00

I’m currently working on a solution, where there are the concepts of users, work

  • 0

I’m currently working on a solution, where there are the concepts of users, work queues and work items. At a basic level a user has a series of work queues assigned to them, the work queue containing the work that is to be done.

So – at the moment we have a basic Linq query that returns all of the queues, but I was hoping to restrict that query to improve performance – based on the current query it pulls back over 94,000 records for a maximum of 127 work queues. The reason for this is that in this linq query we include the WorkItems, so that we can (later on) count the number of work items in the queue. I have extended the WorkQueue object to inclde a LinqQuery to count the number of records – which I hoped would work, but that fails to work unless the initial query includes the workitems.

This is basically to be databound using a master / detail type interface, and I’m somewhat concerned that (based on the Trace String generated from LINQ) that there is a huge amount of data produced which will affect performance.

Historically I would have used straight SQL binding – but the previous developer had decided to use EF for this.. I’m also hampered by the fact that we’re still using version 1 of the Entity Framework Modelling system.

I have considered replacing the query with a Stored Procedure call – but that doesn’t seem to work so well either – giving me an additional NULL record. I’ve tried using LinqPad – and that sort of works, but as soon as you want to include things, the syntax goes to pot.

Here’s what I have so far…

Here’s the Linq Query :

QueueTable.DataSource = From queue In objImageViewerContext.WorkQueues().Include("WorkItems") _
                                        .Where(Function(i) i.Scan_Type = Constants.Work_Queue_Type_Front_End) _
                                        Order By (queue.WorkItems.Count > 0) Descending, queue.Name Ascending

Here’s the SQL that’s generated…

SELECT     WorkQueue_ID, Name, Work_Type, Functional_Area, Process, Text_Code, Barcode, Scan_Type, SLA_Minutes, Medical_Indicator, IsTeamQueue, 
                      C2 AS C1, Role_ID, C4 AS C2, C3, WorkItem_ID, Participant, Last_Action, Last_Modified, Date_Added, Modified_By, Is_Urgent_Action, Image_ID, 
                      Queue_ID
FROM         (SELECT     CASE WHEN ([Project2].[C1] > 0) THEN CAST(1 AS bit) WHEN (NOT ([Project2].[C2] > 0)) THEN CAST(0 AS bit) END AS C1, 
                                              Project2.WorkQueue_ID, Project2.Name, Project2.Work_Type, Project2.Functional_Area, Project2.Process, Project2.Text_Code, 
                                              Project2.Barcode, Project2.Scan_Type, Project2.SLA_Minutes, Project2.Medical_Indicator, Project2.IsTeamQueue, Project2.Role_ID, 
                                              1 AS C2, Extent4.WorkItem_ID, Extent4.Image_ID, Extent4.Queue_ID, Extent4.Participant, Extent4.Last_Action, Extent4.Last_Modified, 
                                              Extent4.Date_Added, Extent4.Modified_By, Extent4.Is_Urgent_Action, CASE WHEN ([Extent4].[WorkItem_ID] IS NULL) THEN CAST(NULL 
                                              AS int) ELSE 1 END AS C3, CASE WHEN ([Extent4].[WorkItem_ID] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS C4
                       FROM          (SELECT     WorkQueue_ID, Name, Work_Type, Functional_Area, Process, Text_Code, Barcode, Scan_Type, SLA_Minutes, 
                                                                      Medical_Indicator, IsTeamQueue, Role_ID, C1,
                                                                          (SELECT     COUNT(CAST(1 AS bit)) AS A1
                                                                            FROM          WorkItems AS Extent3
                                                                            WHERE      (Project1.WorkQueue_ID = Queue_ID)) AS C2
                                               FROM          (SELECT     WorkQueue_ID, Name, Work_Type, Functional_Area, Process, Text_Code, Barcode, Scan_Type, SLA_Minutes, 
                                                                                              Medical_Indicator, IsTeamQueue, Role_ID,
                                                                                                  (SELECT     COUNT(CAST(1 AS bit)) AS A1
                                                                                                    FROM          WorkItems AS Extent2
                                                                                                    WHERE      (Extent1.WorkQueue_ID = Queue_ID)) AS C1
                                                                       FROM          WorkQueues AS Extent1
                                                                       WHERE      (N'Front End' = Scan_Type)) AS Project1) AS Project2 LEFT OUTER JOIN
                                              WorkItems AS Extent4 ON Project2.WorkQueue_ID = Extent4.Queue_ID) AS Project3

It’s so frustrating because I know I can write the SQL to accomplish what I want, I just don’t seem to be able to get Linq to work.

  • 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-17T15:17:24+00:00Added an answer on May 17, 2026 at 3:17 pm

    You can start to optimize this by using a .Select() to only retrieve the columns you care about and possibly use paging with .Skip().Take()

    Also, instead of grabbing all of the WorkItems why don’t you use a select statement such as:

    .Select(i => new { Count = i.WorkItems.Count() })
    

    and get rid of .Include(“WorkItems”) if all you need is a count of WorkItems.

    Sorry I’m using C#, I never write in VB but trust you understand what I’m trying to say

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

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.