1

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

freddoo
  • 6,770
  • 2
  • 29
  • 39

1 Answers1

1

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.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Our Catalog is static and doesn't change during the lifetime of the web application and yes it will create an enormous results set ( yes gigs of data) but it all preloads on application start. I have just read the link that you included very instructive on the .Include part. Now I know not to use the .Include. My original question was how can I preload the Tree and it looks like using .Include is loading a table instead of a tree. How can I preload as a tree ? – freddoo Jun 01 '11 at 15:30