Author: mpaterson | Posted on: 7/23/2008 8:02:58 AM | Views : 323

I'm using Linq to SQL via a stored procedure.
Something like this:
var result = ctx.MyStoredProcedure();
However, I only want the first record back so I figure I have a few options:

var result = ctx.MyStoredProcedure.First();
var result = ctx.MyStoredProcedure.ElementAt(0);

However, I get an exception if no records exist.

So... I wanted to see if I could get result.Count() > 0 but then I get an exception saying I can only enumerate the result set once.

Any ideas as to how I can gracefully utilize LINQ to get ONLY the first record IF one exists?
...

Go to the complete details ...