Skip to content

@khalidabuhakmeh /RavenDB.cs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
RavenDB If extension method
// usage
_db.Query<Story, Stories_Search>()
.If(status.HasValue, q => q.Where(x => x.Status == status))
.If(!curatorId.IsEmpty(), q => q.Where(x => x.CuratorId == curatorId))
.If(publicationDate.HasValue, q => q.Where(x => x.ProposedPublicationDate == publicationDate.Value.Date))
.OrderByDescending(x => x.CreatedAt)
.ToPagedList(page, size);
// extension methods
public static IRavenQueryable<T> If<T>(this IRavenQueryable<T> query, bool should, params Func<IRavenQueryable<T>, IRavenQueryable<T>>[] transforms)
{
return should ? transforms.Aggregate(query, (current, transform) => transform.Invoke(current)) : query;
}
public static IDocumentQuery<T> If<T>(this IDocumentQuery<T> query, bool should, params Func<IDocumentQuery<T>, IDocumentQuery<T>>[] transforms)
{
return should ? transforms.Aggregate(query, (current, transform) => transform.Invoke(current)) : query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.