Now for every entity, a separate query is fired to the SQL Server. If you have associations between this tables, for optimization of queues you should use Fetch Plans API
provided by Telerik OpenAccess ORM
. Using Fetch Strategy
class and LoadWith<T>
method will provide you with immediate loading of related data to the main target in one queue.
I have modified your original code assuming there are associations between Product
. See the code how the navigation properties that implement these associations are used. I have also defined a fetch strategy that instructs OpenAccess
to load all required data in just two queries
and that will improve the performance of your code tremendously.
Here is the modified code that uses Fetch Strategy
and navigation properties
FetchStrategy fetchStrategy =
fetchStrategy.LoadWith<Product>(c => c.Prices);
//refers to the data found in dbContext.PriceLists
fetchStrategy.LoadWith<Product>(c => c.Gallery);
//refers to the data found in dbContext.ProductGalleries
dbContext.FetchStrategy = fetchStrategy;
var plist = dbContext.Products.Where(x => x.Category == cid && x.To_display ==
ProductDM temp =
temp.ProductName = prod.Name_en;
temp.ProductID = prod.Product_id;
temp.Detail = prod.Detail_en;
// original code
//var prlist = dbContext.PriceLists.Where(x => x.Product_id == prod.Product_id);
// prices are already loaded using the fetch strategy
// and they are associated with the right Product instance
var prlist = product.Prices;
// original code
//var pimgs = dbContext.ProductGalleries.FirstOrDefault(x => x.Product_id == prod.Product_id);
// gallery is already loaded using the fetch strategy
// and it is associated with the right Product instance
var pimgs = product.Gallery;
//should we check if pimgs == null?
temp.SmallImage = pimgs.Summary;
temp.BigImage = pimgs.Image1;
If you don't have associations between tables, you can not use Fetch Plans. First you should create associations
, and after that use Fetch Strategy
If you need any further assistance do not hesitate to contact us.
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.