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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With