+6  A: 

Use FirstOrDefault instead of First. This will return null in the face of an empty collection.

IRepository<User> = new UserRepository();
User user = userRepository.FirstOrDefault(u => u.Name == userName);
JaredPar
I won by two seconds...! ;)
Tomas Lycken
@Tomas, I actually got in ahead of you but I made a post answer edit to actually include a code sample. The second edit was 2 seconds behind :)
JaredPar
Thats true Jared got in first :D (by 2 seconds.. it was showing Jared 48 secs ago and Tomas 46 secs ago).Thank you Gentlemen!!!!
Alex
+3  A: 

Try changing .First() to .FirstOrDefault().

Tomas Lycken
+2  A: 

Use .FirstOrDefault() to prevent that error

ichiban
A: 

There are many different way to implement this. you could try:

IRepository<User> = new UserRepository();
User user = userRepository.Where(u => u.Name == userName).Take(1).DefaultIfEmpty;
miti737