什么是“用单个调用替换为单个"?意思是? [英] What does "Replace with single call to single" mean?

查看:56
本文介绍了什么是“用单个调用替换为单个"?意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将LINQ与Single()一起使用时,我的代码行始终以绿色下划线显示,并建议用单次调用替换为Single".这是什么意思?这是产生该建议的一行代码的示例:

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();

如您所见,我只使用Single()一次.那...怎么了?

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

推荐答案

我认为这意味着使用 Single 的重载,它使用谓词而不是同时使用WhereSingle:

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);

这篇关于什么是“用单个调用替换为单个"?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆