I have methods that then chain on to others, passing IQueryable. Here's a cut down sample.
public static IQueryable<Deal> Deals(this DbContext context)
{
Guard.ThrowIfNull(context, "context");
var r = new ReadRepo<Deal>(context);
return r.FindBy()
.Include("Deals_SitePost")
.Include("Deals_CommunityPost")
.Include("Deals_Preorder")
.Include("Deals_Product")
.Include("Deals_Sale")
.Include("Deals_VoucherCode")
.Include("DealSubcategories");
}
public static IQueryable<Deal> ByStore(this IQueryable<Deal> deals, int storeId)
{
return deals.Where(d => d.StoreId == storeId);
}
public static IQueryable<Deal> WhereFeatured(this IQueryable<Deal> deals)
{
return deals.Where(d => d.Deals_SitePost.IsNotNull() && d.Deals_SitePost.IsFeatured);
}
As you can see, there is a starter 'Deals' and a couple of extension methods that I use to extend the query.
In this scenario is is wise to check and return where !IQueryable.Any() in terms of performance before the query statement, or will it not matter?
Stopwatch
or like wise and post it as an answer,