LINQ extension methods - Any() vs. Where() vs. Exists()

后端 未结 7 1669
清酒与你
清酒与你 2020-12-02 19:51

Unfortunately the names of these methods make terrible search terms, and I\'ve been unable to find a good resource that explains the difference between these methods--as in

相关标签:
7条回答
  • 2020-12-02 20:29
    foreach (var item in model.Where(x => !model2.Any(y => y.ID == x.ID)).ToList())
    {
    enter code here
    }
    

    same work you also can do with Contains

    secondly Where is give you new list of values. thirdly using Exist is not a good practice, you can achieve your target from Any and contains like

    EmployeeDetail _E = Db.EmployeeDetails.where(x=>x.Id==1).FirstOrDefault();
    

    Hope this will clear your confusion.

    0 讨论(0)
提交回复
热议问题