实体框架:AttachAsModified故障/混淆:) [英] Entity Framework: AttachAsModified failure / confusion :)

查看:89
本文介绍了实体框架:AttachAsModified故障/混淆:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我试过谷歌,没有得到很多点击。我不想滥用所以,但这是最好的问题之一,EF没有很好的记录。



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



这是序列...



我把CmsProductCategory下拉到Wcf。
我进行更改。
我调用Wcf更新方法...

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

哪些调用域服务方法...

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

这应该工作 - 但不,它在GetOriginal()失败。我觉得我在代码修改它之间缺少一个步骤,并将其传递给Wcf。



任何提示/指向好的文档的指针



谢谢!

解决方案

你的问题可能是你失去了上下文 p>

当您打电话来更新this.Context与您从中读取的内容不一样。



WCF具有每个呼叫和每个会话的概念。 每个呼叫是默认的,因此您将得到一个新的域服务实例。您可以使用每个会话来解决问题。



查看此链接: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx



还尝试编写测试来检查您正在做的工作,而不会通过wcf传输数据。


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!

解决方案

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.

这篇关于实体框架:AttachAsModified故障/混淆:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆