Created
May 19, 2014 10:17
-
-
Save CosminLazar/77ad7ca70cd7ece7d32e to your computer and use it in GitHub Desktop.
Extension class adding FirstOrDefaultLazy to RavenDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class RavenDBExtensions | |
{ | |
public static Lazy<T> FirstOrDefaultLazy<T>(this IQueryable<T> query, Func<T, bool> predicate) | |
{ | |
if (query == null) throw new ArgumentNullException("query"); | |
if (predicate == null) throw new ArgumentNullException("predicate"); | |
return query.Where(x => predicate(x)).FirstOrDefaultLazy(); | |
} | |
public static Lazy<T> FirstOrDefaultLazy<T>(this IQueryable<T> query) | |
{ | |
if (query == null) throw new ArgumentNullException("query"); | |
var lazyResults = query.Lazily(); | |
return new Lazy<T>(() => lazyResults.Value.FirstOrDefault()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment