Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where is context.Entry()?

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; }     } 
like image 274
Babak Fakhriloo Avatar asked Aug 18 '11 20:08

Babak Fakhriloo


People also ask

What is context entry?

The entry provides access to change tracking information and operations for the entity. This method may be called on an entity that is not tracked. You can then set the State property on the returned entry to have the context begin tracking the entity in the specified state. C# Copy.

Where is DB context?

A DbContext instance represents a combination of the Unit Of Work and Repository patterns such that it can be used to query from a database and group together changes that will then be written back to the store as a unit. DbContext is conceptually similar to ObjectContext.

What is entry in C#?

Entry(Object)Gets a DbEntityEntry object for the given entity providing access to information about the entity and the ability to perform actions on the entity. C# Copy. public System.Data.Entity.Infrastructure.


1 Answers

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

like image 90
John x Avatar answered Sep 29 '22 17:09

John x