Short answer: stick with Any ().
You can safely ignore the message you are referring to, because it is not specific to the Entity Framework. When using LINQ over simple collections, yes, there may be other considerations. But when using LINQ to query a database, you want to avoid reusing additional database records unnecessarily.
In this case, you will say that Count () turned out to be faster than Any (). But the difference you experienced is so minimal, at least in terms of database performance, that you can say that in this case you got equivalent performance.
And essentially, if your table is small or if the column you are looking for is correctly indexed and returns very few records, you can expect performance to be pretty similar to Any () and Count ().
But let's say you have a large table and your ExternalId column is not indexed, then you will inevitably notice that Any () is significantly superior to Count ().
Point: the best scenario (if your data model is optimized), both options can work in a similar way. In the worst case, Any () will completely outperform Count ().
There is never a scenario in which Count () will far outperform Any () if EF does not present a serious SQL generation error. Therefore, to be safe, I recommend you stick with Any ().
sstan source share