I was just getting some products using entity framework and was wondering which would be better to do when getting the results, or if there is no difference.
Option 1 - Query the context directly
return dbContext
.PPCProducts
.Include(p => p.Attributes)
.Include(p => p.ChildProducts)
.Where(p => p.Attributes.FirstOrDefault(a => a.AttributeName.IndexOf(attributeName, StringComparison.InvariantCultureIgnoreCase) > -1) != null)
.OrderBy(p => p.ProductName)
.ToList();
Option 2 - Query the cache
// cache the products
var products = dbContext
.PPCProducts
.Include(p => p.Attributes)
.Include(p => p.ChildProducts);
CacheHelper.Add("products", products, CacheDuration.Hours3);
// query the cache
return ((List<Product>)HttpContext.Current.Cache["products"]).Where(p => p.Attributes.FirstOrDefault(a => a.AttributeName.IndexOf(attributeName, StringComparison.InvariantCultureIgnoreCase) > -1) != null)
.OrderBy(p => p.ProductName)
.ToList();