Skip to content

Instantly share code, notes, and snippets.

@CosminLazar
Created May 19, 2014 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CosminLazar/77ad7ca70cd7ece7d32e to your computer and use it in GitHub Desktop.
Save CosminLazar/77ad7ca70cd7ece7d32e to your computer and use it in GitHub Desktop.
Extension class adding FirstOrDefaultLazy to RavenDB
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