Preload Entity Framework 4 tree
I would like to preload my catalog in my web application. I'm using EF4 and would like to prefetch all my catalog data. Is there a simple way to do it with EF4 ?
DB structure : Catalog -> Category -> [Category ->] product -> options
How can 开发者_运维百科I preload all objects on application start ?
Thanks
You can simply call:
var data = context.Catalogs.Include("Categories.Products.Options").ToList();
I assume that Catalog
has navigation property Categories
, Category
has navigation property Products
and Product
has navigation property Options
. This will probably create enormous result set.
Pre-loading such big amount of data usually doesn't make any sense. I would say don't do it and load data on demand when you need them. Pre-loading make sense for data which do not change and present almost on every page you show to clients.
精彩评论