编写查询语句时,经常要用到if exist的判断方法。
list的lambda表达式中可以有
List<Agent> agentList = new List<Agent>();
agentList.Exists(t => t.Id == 1);
但是你会发现无法直接用于linq to SQL中:
System.NotSupportedException: 'LINQ to Entities does not recognize the method 'Boolean Exists(System.Predicate`1[System.Int32])' method, and this method cannot be translated into a store expression.'
可以换list.any的方法可以达到同样的目的:
agentList.Any(t => t.Id == 1);