Click here to Skip to main content
14,266,859 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi,

what is the error of below code....

Sport spt = null;

            if(id != null)
            {
                spt = Db.Coaches.Where(i => i.CoachID == id).First();
            }


Thank you
Posted
Comments
   
The mistake? It depends on what you wanted to take... :-)
Ah, I remember you... :-) Okay, good luck.
—SA
Richard MacCutchan 11-Mar-14 5:01am
   
It doesn't work?
phil.o 13-Mar-14 9:03am
   
How about describing your problem?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You should replace .First() with .FirstOrDefault() to manage in this way also the case when there is no result!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100