English 中文(简体)
EF4尽管我不相信会添加反对内容。
原标题:EF4 can’t add an object to the context even though I’m convinced it is not attached

尽管我相信,它不附属于它,而且与另一个不同背景没有关系,但我还是没有加入反对。

I am using EF 4 with POCO objects.

如果是我,

_currentContext.ObjectStateManager.GetObjectStateEntry(entityIn)

然后,我发现错误。

The ObjectStateManager does not contain an ObjectStateEntry with a reference to an object of type  System.Data.Entity.DynamicProxies.OrderItem_7D361CB49D75AA90681B4BA3F924139ECB0FC1426E38E90C7B884A4E9CD777DF .

做得不够。 因此,如果我试图随函附上它的话。

_currentContext.AttachTo("OrderItems", entityIn)

Then I get

An entity object cannot be referenced by multiple instances of IEntityChangeTracker.

我怎么会发现这两个错误。 难道他们不矛盾吗? 我如何看待这个问题?

<><>Edit>/strong>

There is only one context throughout the app. The pattern is

  1. All calls through repository objects.
  2. The objects get their objectcontext from a factory class.
  3. This factory class either creates a context or gets the context from the request object thus guaranteeing only one context is used for the page lifecycle

无论在什么时候,如果你对情况作两场即时表示反对,则每一方的散射代码相同。

最佳回答

标 题 在中,可能提及另一个情况下的物体。

However, the real problem here is that you have multiple contexts in scope at all. It is hard to do that right. In a web application, you should have one context per request, period.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签