views:

870

answers:

2

Ok... I tried google and didn't get many hits. I dont want to abuse So but this is one of the best places to ask and EF isn't well documented.

My fails because the GetOriginal() returns null in UpdateCmsProductCategory. I assume that means currentCmsProductCategory is not in the ChangeSet. Ok... how do I put it in the changeset?

Here is the sequence...

I pull a CmsProductCategory down over Wcf. I make changes. I call the Wcf update method...

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

Which calls the Domain servide method...

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

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

Any hints / pointers to good documentation?

Thanks!

+1  A: 

Your problem is probably that you lose the "context".

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

WCF has a concept of "per call" and "per session". The "per call" is default your are therefore getting a new instance of the domain service. You may be able to solve it using per session.

Have 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 works without transfering the data over wcf.

Shiraz Bhaiji
A: 

Hi, I have the same problem. But i am not using WCF, i am using the Asp.net dynamic data website. Below are more details:

In my dynamic data website i wish to update the 'IsDeleted' flag rather than deleting a record.(Soft Delete)

So under my domain service class in my public void DeleteContact(Contact contact) method i have called the following code

Contact originalContact1 = this.ChangeSet.GetOriginal(contact);

contact.IsDeleted= true;

this.Context.AttachAsModified(contact, originalContact1);

However i always get the originalContact1 as NULL.

Does the this.ChangeSet.GetOriginal(contact); method doesnt work under the delete() method, does it only work under the Update() method.

Please suggest, how can i perform this task.