Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Replace with single call to single" mean?

Tags:

When using LINQ with Single() I always get my line of code underlined in green with the suggestion "Replace with single call to single." What does this mean? Here's an example of a line of code that results in that suggestion:

var user = db.Users.Where(u => u.UserID == userID).Single(); 

As you can see I'm only using Single() once. So... what's the deal?

like image 538
Legion Avatar asked Jun 10 '13 20:06

Legion


1 Answers

I assume it means, use the overload of Single which takes a predicate instead of using Where and Single together:

var user = db.Users.Single(u => u.UserID == userID); 
like image 183
Lee Avatar answered Sep 18 '22 17:09

Lee