Click here to Skip to main content
15,887,364 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
hi,

what is the error of below code....

C#
Sport spt = null;

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


Thank you
Posted
Comments
Sergey Alexandrovich Kryukov 11-Mar-14 2:24am    
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

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900