I am using Entity Framework and Caliburn.Micro to implement an MVVM application.
Basically, I have set up AuthorModel and BookModel in a one to many relationship - a
As Eben mentions, the Author
referenced by the ItemsSource
will be a different object (although it happens to reference the same entity).
I think your approach of using a new DbContext
for both of your windows is correct, you can run into problems if you have persisting/shared DbContexts
; it makes sense to load an EditWindow
with a new context, perform your edits, and dispose of the context.
One option is to Detach
your Book
entity from the old DbContext
, and Attach
it to your new context: (a good explanation here Entity Framework 4 - AddObject vs Attach).
I would probably just favour using the passed Book
entity to reload the selected Book
from the new context e.g. using DbSetSelectedItem
(rather than the one you're passing across windows).