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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:34:35+00:00 2026-05-13T00:34:35+00:00

I am using the below statement with the intent of getting all of the

  • 0

I am using the below statement with the intent of getting all of the machine objects from the MachineList collection (type IEnumerable) that have a MachineStatus of i. The MachineList collection will not always contain machines with a status of i.

At times when no machines have a MachineStatus of i I’d like to return an empty collection. My call to ActiveMachines (which is used first) works but InactiveMachines does not.

public IEnumerable<Machine> ActiveMachines
{
    get
    {
        return Customer.MachineList
            .Where(m => m.MachineStatus == "a");
    }
}

public IEnumerable<Machine> InactiveMachines
{
    get
    {
        return Customer.MachineList
            .Where(m => m.MachineStatus == "i");
    }
}

Edit

Upon further examination it appears that any enumeration of MachineList will cause subsequent enumerations of MachineList to throw an exeception: Object reference not set to an instance of an object.

Therefore, it doesn’t matter if a call is made to ActiveMachines or InactiveMachines as its an issue with the MachineList collection. This is especially troubling because I can break calls to MachineList simply by enumerating it in a Watch before it is called in code. At its lowest level MachineList implements NHibernate.IQuery being returned as an IEnumerable. What’s causing MachineList to lose its contents after an initial enumeration?

  • 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-13T00:34:35+00:00Added an answer on May 13, 2026 at 12:34 am

    Where returns an empty sequence if there are no matches; this is a perfectly valid sequence (not null). The only way you’d get a null is if you call FirstOrDefault or SingleOrDefault.

    Are you sure the bug is where you think it is?

    int?[] nums = { 1, 3, 5 };
    var qry = nums.Where(i => i % 2 == 0);
    Console.WriteLine(qry == null); // false
    Console.WriteLine(qry.Count()); // 0
    var list = qry.ToList();
    Console.WriteLine(list.Count); // 0
    var first = qry.FirstOrDefault();
    Console.WriteLine(first == null); // true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when trying to execute this update statement (below) using C#
I am using wordpress and I have an SQL statement (as below) to gather
I am deleting all data from the table by using below code snippet NSString
I am using VS2005 for vb.net. I am getting compile error at below statement.
Using SQL Server 2005 how do I get the below statement or rather the
Am using below third party API in my project development http://undesigned.org.za/2007/10/22/amazon-s3-php-class I have done
I am using below code to generate photo gallery from a folder. How can
I am using below statement for database in tomcat context.xml. Some time it works
I am trying to remove attributes of a DOM element using below statement in
Is the below statement a valid one? persist() also guarantees that it will not

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.