2009-08-27 90 views
2

好的...我试过谷歌并没有得到很多点击。我不想滥用所以,但这是最好的地方之一要求和EF没有很好的记录。实体框架:AttachAsModified失败/混淆:)

我失败了,因为GetOriginal()在UpdateCmsProductCategory中返回null。我认为这意味着currentCmsProductCategory不在ChangeSet中。好的...我如何将它放入变更集中?

这里是序列...

我拉CmsProductCategory下跌超过WCF。 我做了修改。 我调用WCF更新方法...

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

其中要求域servide方法...

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

这应该工作 - 但没有,这对我异常时GetOriginal()失败。我觉得我错过了代码修改它之间的一步,并将其传递给Wcf。

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

谢谢!

回答

1

你的问题可能是你失去了“上下文”。

当您调用更新时,“this.Context”与您阅读的不一样。

WCF具有“每次通话”和“每次通话”的概念。 “每次通话”是默认情况下您正在获取域服务的新实例。您可能能够使用每个会话解决它。

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

也可以尝试写一个测试来检查,你在做什么工作,而不在WCF转化中的数据。