You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.
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:)
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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:)
The text was updated successfully, but these errors were encountered: