3

Possible Duplicate:
Linq .Any VS .Exists - Whats the difference?

Is there a performance difference between using any vs exists in a LINQ query? Specifically LINQ to Entities.

Community
  • 1
  • 1
DCNYAM
  • 11,966
  • 8
  • 53
  • 70
  • 1
    See http://stackoverflow.com/questions/879391/linq-any-vs-exists-whats-the-difference – Ross Jul 14 '11 at 15:59
  • So, according to that post, EXISTS is not a linq method. Therefore, am I to understand that ANY would be the only appropriate method to use to query the database to check if a record exists? – DCNYAM Jul 14 '11 at 16:03
  • 2
    Well in LINQ to Entities, Exists() is not often not even available (on ObjectSet<>, IQueryable<>, etc.) Your only choice is Any(). Exists() will only be available if you first use ToList() in your LINQ queries. – Ross Jul 14 '11 at 16:07

1 Answers1

4

Exists requires an instance of List<T> while Any is invoked on IEnumerable<T>. This means you have the potential for increased memory efficiency as IEnumerable<T> can be evaluated lazily.

ChaosPandion
  • 77,506
  • 18
  • 119
  • 157