Skip to main content


Showing posts from May, 2012

An Entity Framework Stale Data Gotcha

For ASP.Net MVC development I've been working for a while with a setup using Entity Framework Code First and Castle Windsor for providing IoC container services. I recently ran into a weird bug that may be obvious to some... but given I wasted an hour or so working it out figured it was worth a blog post. The issue was that for a certain operation I was getting stale data out of Entity Framework. With the help of the very useful Entity Framework Profiler which was reporting an ObjectContext being shared across threads I tracked it down to my implementation of a custom membership and role provider. For most use of the IoC container I have a custom controller factory, that handles resolving the dependent types. But there are some parts of the application that need access to classes managed through the container, but that aren't within the context of a controller. Custom membership and role providers are examples of these. With Castle Windsor (and other IoC container