31

I wrote my own context by reading this article and many others, but none of theme explains where is this context.Entry(obj) defined, I mean even by reading this article, I cant understand how to implement this method, and I get the following error :

Error 36 'Domain.Entities.OurWebSiteContext' does not contain a definition for 'Entry' and no extension method 'Entry' accepting a first argument of type 'Domain.Entities.OurWebSiteContext' could be found (are you missing a using directive or an assembly reference?)

Somebody help me out please

Edited >>

 public class OurWebSiteContext : DbContext
    {
        public OurWebSiteContext(string connString)
            : base(connString)
        {

        }

        public DbSet<Article> Articles { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<Comment> Comments { get; set; }
    }
Amir Ismail
  • 3,865
  • 3
  • 20
  • 33
Babak Fakhriloo
  • 2,076
  • 4
  • 44
  • 80
  • Did you actually derive `OurWebSiteContext` from `DbContext`: `public class OurWebSiteContext : DbContext`? `Entry` is a public method of `DbContext`. If your application understands `DbContext` it should also know `Entry`. – Slauma Aug 18 '11 at 20:16
  • I edited my question, you can now see OurWebSiteContext definition. – Babak Fakhriloo Aug 18 '11 at 20:23
  • 1
    By reading the "http://msdn.microsoft.com/en-us/data/gg685467" article, I got that it is an version specific problem. Because after doing what this article says, my program executed without any problem. – Babak Fakhriloo Aug 18 '11 at 21:12

1 Answers1

45

may be too late to answer but it may help others, EF 4.0 uses the ObjectContext class where as the version 4.1 uses the DbContext class in which the methods like Set<T> and Entry are defined. With version 4.0 you can do something like

DatabaseContext _context = new DatabaseContext();
_context.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified);

with version 4.1 its done like

_context.Entry(entity).State = System.Data.EntityState.Modified;

here is a useful SO link

Community
  • 1
  • 1
John x
  • 4,031
  • 8
  • 42
  • 67