Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Attaching "nested" models #32

Open
marvealmar opened this issue Jan 23, 2012 · 0 comments
Open

Attaching "nested" models #32

marvealmar opened this issue Jan 23, 2012 · 0 comments

Comments

@marvealmar
Copy link

Hi,

I have a service layer from with I pull some data in a UoW scope. I do some eager fetching the retrieve associated data. Then i perform actions on this model object, change data, adding new entities to an association collection etc. My problem is when I send the changed object back for processing in my service layer. I had some proplem updating the object, getting an error saying something like that the object already exist in the ObjectStateManager. What I did is attaching the "root" object. However this did not result in an update/save of changed properties in the child object. I had to loop each child association and then attach them the their own reposiotory. Something like this:

using (var scope = new UnitOfWorkScope())
{
var rootDomainRepository = new EFRepository();
var childRepos = new EFRepository();
myrootobject.SomeMethod() //argument in service method
myrootobject.Children.ForEach( c => childRepos.Attach(c));
rootDomainRepository.Attach(myrootobject);
scope.Commit();
}

Now, is this the way to do it? Would it be possible to add support for attaching children/association when attaching a parent object? Or am I doing something fundementally wrong:)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant