2

I have a small database, and it will remain small. It is an asp.net 4.0 website. It is small both in terms of number of tables and number of entries in them. Also it is for internal management, so few users will use it.

Is there a way to load everything in one call? Than is, instead of calling context.Orders.ToList(), context.Customers.ToList() and so on.

Moreover, if such option exists, will it load all the entity references as well?

I know it is a weird requirement but I think that in my scenario it will be much more efficient in terms of returning data back.

Thanks, Itye

Itye
  • 135
  • 1
  • 7

3 Answers3

1

No there is no command which will simply load everything to memory. You can start with some entity and define eager loading by using Include method but you can't eager load entities without relation.

Moreover whole this approach smells. Why do you want to do it? You mentioned ASP.NET tag so it seems like you want to share loaded data among clients? That will be very bad idea if your application is not readonly. One context among all concurrent requests is same like sharing "transaction".

ObjectContext should live only to serve single unit of work. In most cases that means single HTTP request in web application.

Community
  • 1
  • 1
Ladislav Mrnka
  • 349,807
  • 56
  • 643
  • 654
0

As far as I know, no such functionality exists. You'd have to call ToList() or ToArray() on every entity set manually.

Going down this road does not seem like a good idea to me. If your database is small, then everything is going to be fast anyway, so I'd recommend just using the Entity Framework as intended. If you really want to load all of the data at once, perhaps you should be using a file instead of a database?

Dave Markle
  • 88,065
  • 20
  • 140
  • 165
0

You would have to explicitly load it; I have not heard of a process that loads the entire context into memory, because as in most scenarios that doesn't work. To load all entity references/collections requires a call to Include too.

Brian Mains
  • 49,697
  • 35
  • 139
  • 249