Misleading suggestion "Replace with a single call to FirstOrFefault()"

in general I'm following the suggestion of Resharper to replace Where(statement).FirstOrDefault() calls to FirstOrDefault(statement) since it's shorter and more elegant.
However the two statements are not identical all the times. For instance LinqToSharepoint does not interpret FirstOrDefault and if it is used directly on the source it means that
it retrieves all the contents of the source and then applies the condition in memory!
I know it's insane... Microsoft should be ashamed for such faulty implementation!
You can read more about it here: http://www.sharepointblues.com/2010/09/08/linq-to-sharepoint-performance-pitfalls/

Comment actions Permalink

As per http://wp.secretnest.info/archives/2991 , Where(..).FirstOrDefault(); can also be *much* faster.
So ReSharper is really suggesting me to make my code worse here.

Comment actions Permalink

Only when it's applied to an array or List<T> instance. Any decent query provider should convert both forms to the same store query.


Please sign in to leave a comment.