In my opinion (which isn't necessarily valid, I have little ASP experience), in this case, the entity definitely shouldn't be using the UnitOfWork, or even be aware of it.
If you already have configured Menu
entities which entity framework is managing, and you have several existing repositories set up to further abstract & manage your database interactions, it doesn't make sense to pollute your model.
I'm assuming the error is appearing because the new UnitOfWork
the other developer has defined in the model is a new context, and the Menu
entity has already been obtained from another context (your MenuRepository
), which you've already figured out.
It seems like the other developer is attempting to load the child MenuItems
if there aren't any present in the Menu
entity, when setting the MenuID. It's not entirely clear to me what's going on there, it seems as if they're expecting the item to have its ID changed, and then wanting to obtain the MenuItems
belonging to Menu
with the new ID (I'm not sure why you'd want to change the ID).
The MenuItem
loading should be possible at the time the entity is retrieved, or afterward depending on how the entities are mapped/configured, using Lazy
, Eager
, or Explicit
loading.
It's certainly worth talking to the other developer and finding out what they're trying to achieve, don't be worried about the amount of experience someone has (or says they have), many of these concepts may be new to them as well, or they may have spent all that time reinforcing bad habits, good programmers should always be willing to have a discussion about various approaches.
Some extra info on loading: http://msdn.microsoft.com/en-us/data/jj574232.aspx