如何使用Linq作为IF条件

rev*_*veN 4 c# linq if-statement

我有一个小的linq查询在数据库中搜索客户:

var query =
   from c in database.customer
   where c.ID == input
   select c;
Run Code Online (Sandbox Code Playgroud)

每个客户都有一个ID,在这种情况下由用户设置 - "输入"

数据库中的所有客户都来自"德国",但有些客户应被复制到具有不同国家价值的数据库中("英格兰"代替"德国")

现在,在将它们直接添加到数据库之前,我想检查数据库中是否已存在此客户的"英文版".

if (query.Where(c => c.country == "England"))
   //do nothing
else 
   //add the customer with c.country = "England"
Run Code Online (Sandbox Code Playgroud)

问题是这不是一个常规的if语句.

有没有可能的方法来达到我想在这个条件下表达的内容?

谢谢

Jar*_*lec 8

只是改变条件

if (query.Any(c => c.country.Equals("England")))
   //do nothing
else 
   //add the customer with c.country = "England"
Run Code Online (Sandbox Code Playgroud)

Linq方法Where返回IEnumerable值wchich无法自动转换为bool值.类似于AnyAll返回truefalse基于条件是否分别true针对集合中的至少一个元素或所有元素的方法.