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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:05:50+00:00 2026-05-30T14:05:50+00:00

Well guys, this problem just baffles me. I hope someone can explain to me

  • 0

Well guys, this problem just baffles me. I hope someone can explain to me what is going on because I think I’m losing my mind… 🙂

The situation is as follows:
In my Index method (MVC2 application), I query the entire content of a table in my database, and insert it into the ‘temp’ variable. I then narrow down the list based on what parameters have been passed to my method.

if (int.TryParse(costcenter, out tempint) && !string.IsNullOrWhiteSpace(costcenter))
     {
            Trace.Write("From " + temp.Count());
            temp = temp.Where(x => x.tbl_CostCenters.Id == tempint);
            Trace.WriteLine(" to " + temp.Count());
     }

if (int.TryParse(supplier, out tempint) && !string.IsNullOrWhiteSpace(supplier))
            {
                temp = temp.Where(x => x.tbl_EquipmentType.tbl_Suppliers.id == tempint);
            }

            Trace.WriteLine(" to " + temp.Count());

These parameters are passed as string, so I convert them to ints, then use a query to filter based on the values (if any). What I noticed was, when I select a CostCenter to filter on (and nothing else, all other variables are null), no results were return. I added some tracing to check how many items should be displayed. Given the 3 Trace.Write command in there, i expected my output to be the following:

From 8989 to 65
 to 65

However, what I get is:

From 8989 to 65
 to 0

Which means something is going amiss in the ‘supplier’-filter. I debugged it and stepped through piece by piece, the program does the following:

  • After writing the ” to 65″ string, the program jumps to the “if(…supplier…)”
  • Debugging watch: tempint = 0, supplier = null
  • The program skips directly to the next Trace.Writeline as the evaluation is false
  • Suddenly, my temp variable contains no elements.

I’m puzzled by this because my method is not executing any command related to the temp variable, yet it gets emptied.
Also, when I comment the “supplier”-filter (the entire IF-block), the code work. The error is occuring in the “Supplier”-filter.

Anyone have an idea as to why this is occuring? Thanks in advance!

UPDATE

If I comment out only the content of the “supplier”-if-block, and keep the if-block itself, it also goes amiss. So the problem is occuring in the evaluation of the if-statement. Am I losing my mind here? 🙁

FURTHER UPDATE

Well, I fixed it by adding .ToList() to every statement so that temp is now an IEnumerable rather than an IQueryable.

I’m still puzzled as to why this is happening. Can anyone explain why it doesn’t work without converting temp to a List?

  • 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-30T14:05:52+00:00Added an answer on May 30, 2026 at 2:05 pm

    Found it out that you need to do a .ToList(), else your query keeps working by reference rather than by value.

    Always do a .ToList() 🙂

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

Sidebar

Related Questions

This should be a simple one for someone. I just can't figure out how
Hi guys got a wired problem (well I find it a wired problem :P)
Alright guys, well, here is the thing. I used this wonderful website and found
Well, I'm having this newbie problem right now. I have 3 JFrames. JFrame1 opens
Hi this is my first post here hope you all are well. So Im
Hey guys, I'm using Twitter's PHP API, called twitterlibphp , and it works well,
Well, I want to check the version of a site (this part I know
Well, we all know there are always XSS vulnerabilities that can be discovered in
Apologies if this has already been covered or you think it really belongs on
Hi guys I'm using this wonderful class here to do a bit of code

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.