实体框架:AttachAsModified失败/混乱:)

时间:2009-08-27 16:37:43

标签: wcf entity-framework ria

好的......我试过google并没有获得很多点击量。我不想滥用,但这是最好的地方之一,EF没有详细记录。

我失败了,因为GetOriginal()在UpdateCmsProductCategory中返回null。我假设这意味着currentCmsProductCategory不在ChangeSet中。好的...我怎么把它放在变更集中?

这是序列......

我将Wms上的CmsProductCategory拉下来。 我做了改变。 我称之为Wcf更新方法......

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

调用Domain servide方法......

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

这应该有效 - 但不是,当GetOriginal()失败时,我就会例外。我觉得我错过了代码修改它并将其传递给Wcf之间的一步。

任何有关良好文档的提示/指示?

谢谢!

1 个答案:

答案 0 :(得分:1)

你的问题可能是你失去了“背景”。

当您进行更新调用时,“this.Context”与您从中读取的内容不同。

WCF具有“每次通话”和“每次会话”的概念。 “每次调用”是默认的,因此您将获得域服务的新实例。您可以使用每个会话解决它。

请看一下这个链接:http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

另外尝试编写测试以检查您正在做什么而不通过wcf传输数据。