“ObjectContext的'不包含'进入',没有扩展方法'入口'的定义 [英] 'ObjectContext' does not contain a definition for 'Entry' and no extension method 'Entry'

查看:186
本文介绍了“ObjectContext的'不包含'进入',没有扩展方法'入口'的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

目前的状态是删除

这就是我想要做的:

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

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

所以,我在想什么?

修改

我的的NuGet 输出:

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

解决方案

您正在使用<一个href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"><$c$c>ObjectContext,它不具备输入方法。你必须使用<一个href="http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext%28v=vs.103%29.aspx"><$c$c>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.

这篇关于“ObjectContext的'不包含'进入',没有扩展方法'入口'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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