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

New Post: Performance issues

$
0
0

I've found that a DbContext is quite a bit more expensive to create than an NHibernate session. Just like you reuse your NHibernate session factory, so can you reuse a DbContext.

However, DbContext isn't threadsafe so when I have a class that is going to be called from many threads I manage my context with a thread local variable like this:

    private readonly ThreadLocal<DataContext> _contextProvider = new ThreadLocal<DataContext>(() => new DataContext());

Then in the method I just use _contextProvider.Value as I would a new context.

Brad


Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>