Entity Framework: AttachAsModified crash / confusion :)

Ok ... I tried Google and didn't get many hits. I don't want to overuse So, but this is one of the best places to ask, and EF is not documented.

My error is because GetOriginal () returns null in UpdateCmsProductCategory. I am assuming currentCmsProductCategory is not in the ChangeSet. Ok ... how do I put it into a changeset?

Here's the sequence ...

I am pulling CmsProductCategory down the Wcf. I'm making changes. I am calling the Wcf update method ...

public void UpdateProductCategory(CmsProductCategory category)
{
    domainservice.UpdateCmsProductCategory(category);
}

      

Which calls the domain service method ...

public virtual void UpdateCmsProductCategory(CmsProductCategory currentCmsProductCategory)
{
    this.Context.AttachAsModified(currentCmsProductCategory, 
        this.ChangeSet.GetOriginal(currentCmsProductCategory));
}

      

And that should work - but no, these are Exceptions on me when GetOriginal () fails. I feel like I am missing a step between when the code changes it and I pass it to Wcf.

Any hints / pointers to good documentation?

Thank!

+2


source to share


1 answer


Your problem is probably that you are losing "context".

When you make a call to update "this.Context" it is not the same as what you read it.

WCF has the concept of "per call" and "per session". "For each call" is the default, so you get a new instance of the domain service. You can solve it with a session.



Take a look at this link: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

Also try writing a test to check that what you are doing is not transferring data over wcf.

+1


source







All Articles