codeice / linqtoexcel

Automatically exported from code.google.com/p/linqtoexcel
0 stars 0 forks source link

Cannot handle empty result using .FirstOrDefault(?) #22

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It appears that .FirstOrDefault() and all similar methods for handling no
rows returned is not supported(?)

What steps will reproduce the problem?

Execute the following query:

   var agency = (from a in repo.Worksheet("Accounts")
                 where a["Account No"].ToString() == "bogusAcct#"
                 select a["Agency"]).FirstOrDefault();

The column names are all correct, just the lookup value is not present in
the data. Instead of a null result (as expected), it throws either a
InvalidOperationException ("Sequence contains no elements") or a
NullReferenceException.

How do I check for an empty result set without wrapping everything in a
try/catch block?

Using latest version (downloaded today) on Windows Server 2008 in VS 2008.

Original issue reported on code.google.com by toomey.d...@gmail.com on 5 May 2010 at 3:58

GoogleCodeExporter commented 8 years ago
This has been fixed in the latest download (LinqToExcel_1.3.70)

Original comment by paulyo...@gmail.com on 12 May 2010 at 5:22