Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Caching and lazy loaded parent-child relationships

$
0
0
@saveliev The short answer is no, it will not work correctly. DbContext is not thread safe, so anything done with a context instance should be done by only one thread at a time. Also, it is true that the proxies keep a reference to the context to enable lazy loading, but the proxies never stop the context from being disposed, and once the context is disposed lazy loading will fail. Therefore you will need to make sure that the context lifetime is managed in such a way that it will not be disposed before all lazy loading has been done. Of course, it is also important that the context is eventually disposed. Finally, it is usually quite hard to reconcile all this with a short-lived context responsible for a unit of work, which is a general best practice for using EF.

Thanks,
Arthur

Viewing all articles
Browse latest Browse all 1793

Trending Articles