I have an ASP.NET MVC application using the Entity Framework for a data layer.
In one of my methods, I get data on the seasonal availability of the product, and then the best tax rate for the product.
public ProductList FetchProductSearchList(ProductSearchCriteria criteria)
{
...
var avail = ProductAvailabilityTemplate.Get(criteria.ProductID);
...
var tr = TaxRate.BestMatchFor(criteria.ProductID, criteria.TaxCode);
...
}
In the data layer for ProductAvailabilityTemplate.Get, I optimized the performance of my LINQ code. In particular, I installed ctx.ObjectContext.ContextOptions.LazyLoadingEnabled = false;to prevent the loading of some objects (via navigation properties) that I do not need in this scenario.
However, as soon as this change was made, I noticed that my TaxRates were not fully loaded because it ctx.ObjectContext.ContextOptions.LazyLoadingEnabledwas still false in my tax data level code. This meant that the object associated with TaxRate through the navigation property was not loaded.
, ctx.ObjectContext.ContextOptions.LazyLoadingEnabled = true; , , . , , , . , , , .
.