“ObjectContext的'不包含'进入',没有扩展方法'入口'的定义不包含、入口、定义、方法

2023-09-02 23:59:05 作者:闭眼听风

我升级我的 EntityModel 来版 4.3 使用的NuGet

现在我想改变我的 EntityObject.State ,但它不能找到 .Entry()方法。

目前的状态是删除

这就是我想要做的:

someObjectContext.Entry(someEntityObject).State = EntityState.Unchanged;

在referances到的EntityFramework和EntityFramework.Extended添加。

所以,我在想什么?

OCNet Object Context Network for Scene Parsing Microsoft Research 论文解析

修改

我的的NuGet 输出:

  PM>安装,包装的EntityFramework -Version 4.3.1
的EntityFramework 4.3.1已安装。
数据已经引用了的EntityFramework 4.3.1。
 

解决方案

您正在使用ObjectContext,它不具备输入方法。你必须使用DbContext,这是围绕的ObjectContext 与其他方法的包装,加入EF 4.3 4.1(修正感谢Slauma)据我记得 - 也有一个方法来提取的的ObjectContext 的DbContext 在需要的时候:

  ObjectContext的背景下=((IObjectContextAdapter)yourDbContext).ObjectContext;
 

下面是周围的其他方式:

 的DbContext上下文=新的DbContext(yourObjectContext,真正的); //还是假的,取决于你想要什么
 

下面是一个链接的构造。

I upgraded my EntityModel to version 4.3 using NuGet.

Now i want to change my EntityObject.State, but it cant find the .Entry() method.

The current state is Deleted.

This is what i want to do:

someObjectContext.Entry(someEntityObject).State = EntityState.Unchanged;

The referances to EntityFramework and EntityFramework.Extended are added.

So, what am i missing?

EDIT

My NuGet output:

PM> Install-Package EntityFramework -Version 4.3.1
'EntityFramework 4.3.1' already installed.
Data already has a reference to 'EntityFramework 4.3.1'.

解决方案

You're using ObjectContext, which does not have the Entry method. You'd have to use DbContext, which is a wrapper around ObjectContext with additional methods, added in EF 4.3 4.1(correction thanks to Slauma) as far as I remember - also there's a way to extract the ObjectContext from DbContext when needed:

ObjectContext context = ((IObjectContextAdapter)yourDbContext).ObjectContext;

Here's the other way around:

DbContext context = new DbContext(yourObjectContext, true); //or false, depends what you want

Here's a link to the constructor.