I use the following statement to get all the machine objects from the MachineList collection (type IEnumerable) that have MachineStatus i. The MachineList collection MachineList not always contain machines with i status.
Sometimes, when no machines have MachineStatus i, I would like to return an empty collection. My call to ActiveMachines (which is used first) works, but InactiveMachines does not work.
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 seems that any MachineList enumeration will lead to subsequent MachineList enumerations to throw an exeception: Object reference not set to an instance of an object .
Therefore, it does not matter if the call to ActiveMachines or InactiveMachines called as a problem with the MachineList collection. This is especially troubling because I can break MachineList calls simply by listing it in a Watch before calling it in code. At the lowest level, MachineList implements NHibernate.IQuery , returned as IEnumerable . What causes MachineList to lose content after the initial enumeration?
c # lambda linq ienumerable
ahsteele
source share