Using the latest EF Code First CTP in an asp.net web app, I seem to have run into an issue. Please excuse the lack of code (for now) but I'll try to explain well.
In my controllers, I am injecting a repository factory and an IDataContext via my DI container. The IDataContext is just an interface to my DbContext and the repository factory itself will be injected with one of these also.
My problem is, when retrieving a user from the a repository (from the factory) and then adding some properties inside a using(DataContext) block - the IDataContext that is injected, the changes do not get saved.
If I create a new user - that works fine. But when I add Records to the user's ICollection they do not persist.
I created a test to use one DataContext to create the user, and then another DataContext - both in using blocks - to add records. And it works fine (in this create-dispose-create-dispose sequence).
My guess is that in the controllers, the different instances of IDataContext are affecting commands sent to the database - or even before then..
I should have the problem nailed tomorrow. But any suggestions would still be nice if I don't manage to track down the issue.
I managed to fix it. Basically I just needed to tell the DependencyResolver that instances of my DbContext were per-request.
Hope this saves somebody hassles some time.