Thursday 15 July 2010

c# - Return an empty collection when Linq where returns nothing -


I'm using the following statement with the intention of getting all the machine objects from MachineList I'm i of machinestats in the collection (type IEnumerable). The machine list collection will not always be the machine with the status of i .

Sometimes when there is no machine, I want to return a blank archive of MachineStatus i . My call works with ActiveMine (which is used earlier), but does not passive matches .

  Public INMMerable & lt; Machine & gt; ActiveMenance {Return Clients.Machinist. Where (M => M. Mccinstats == "A"); }} Public IEnumerable & lt; Machine & gt; Passive Matches ({Return Customers.MachineList, where (M => M. Mccinstatus == "I"); On the further examination it appears that any enumeration of  machine list  The reason for the subsequent enumeration is: 

Edit

: machine list to throw an exeception: Object reference

is not set for the example of the object. Therefore, it does not matter if the call is made MachineList As a problem ActiveMachines or passive matchbox this is particularly troubling because I write it in the clock before being told in the code just by MachineList . The lowest level is applied to machine list is being returned as NHibernate.IQuery a IEnumerable What is the reason for losing its contents after the initial countdown?

< P> Where there is no match, there is a blank sequence ; This is a perfectly valid sequence (not faucet). If you call first and default or SingleOrDefault , then you are the only way to get one tap.

Are you really a bug, where do you think it is?

  int? [] Nums = {1, 3, 5}; Var qry = nums..Where (i => i% 2 == 0); Console.light line (curie == zero); // false console Row (qry.Qount ()); // 0 var list = qry.ToList (); Console.WriteLine (list.Count); // var first = qry.FirstOrDefault (); Console.lightline (first == faucet); // true  

No comments:

Post a Comment