Salman Aziz
Salman Aziz

Reputation: 381

Cached entities making round trip to database

i am caching objects, if i make linq queries on cached entities then... will theses queries make database round trip due to lazy loading in Entity framework?

Upvotes: 0

Views: 124

Answers (1)

Eranga
Eranga

Reputation: 32437

If you do not detach the entities before you caching them the entities will keep a reference to the context that created them and use it to lazy load. It is better to detach the entities.

context.Detach(entity);
cachedItems.Add(entity);

Upvotes: 1

Related Questions