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

  • Home
  • SEARCH
  • 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 3791774
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:31:15+00:00 2026-05-19T12:31:15+00:00

I have a query that’s running slow (in a loop of about 100 it

  • 0

I have a query that’s running slow (in a loop of about 100 it takes 5-10 seconds) and have no clue why. It’s simply querying against a List of objects… your help is much appreciated!

I’m basically querying for Schedules that have been assigned to specific managers. It must be from the specified Shifts week OR the first 2 days of next week OR the last 2 days of the previous week.

I tried calculating .AddDays before but that didn’t help. When I ran a performance test it highlighted the “from” statement below.

List<Schedule> _schedule = Schedule.GetAll();
List<Shift> _shifts = Shift.GetAll();

// Then later...
List<Schedule> filteredSchedule = (from sch in _schedule 
                                    from s in _shifts
                                    where
                                        **sch.ShiftID == s.ShiftID
                                        & (sch.ManagerID == 1 | sch.ManagerID == 2 | sch.ManagerID == 3)
                                        & ((s.ScheduleWeek == shift.ScheduleWeek)
                                                | (s.ScheduleWeek == shift.ScheduleWeek.AddDays(7)
                                                        & (s.DayOfWeek == 1 | s.Code == 2))
                                                | (sch.ScheduleWeek == shift.ScheduleWeek.AddDays(-7)
                                                        & (s.DayOfWeek == 5 | s.Code == 6)))**
                                    select sch)
                                    .OrderBy(sch => sch.ScheduleWeek)
                                    .ThenBy(sch => sch.DayOfWeek)
                                    .ToList();
  • 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-19T12:31:16+00:00Added an answer on May 19, 2026 at 12:31 pm

    First port of call: use && instead of & and || instead of |. Otherwise all the subexpressions in the where clause will be evaluated, even if the answer is already known.

    Second port of call: use a join instead of two “from” clauses with a where:

    var filteredSchedule = (from sch in _schedule
                            join s in _shifts on s.ShiftID equals sch.ShiftID
                            where ... rest of the condition ...
    

    Basically that’s going to create a hash of all the shift IDs, so it can quickly look up possible matches for each schedule.

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

Sidebar

Related Questions

Have a query that is failing because the scope is running a query like
I have this query that runs in 7 seconds producing 12,094 records on my
I have a query that checks a database for a match against the input
I have a query that goes something like this: SELECT t1, t2, IF(MATCH(t2) AGAINST
I have a query that is selecting about 20 columns, all are varchars. Some
I have a query that works, but it's taking at least 3 seconds to
I am using in C# MYsql .I have query that works if I run
I have a query that successfully grabs the unique products from my products table
I have a query that basically combines tables of actions and selects from them
I have have this query that i want to execute. SELECT warehouse.expiry_date, pharmacy.expiry_date, drugs.active_substance,

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.