Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

c# - 'ObjectContext' does not contain a definition for 'Entry' and no extension method 'Entry'

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'.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...