How to use context. Set and context. Entry, which ships with EF4.1?
Hello,i am trying to implement a generic repository asExplained on the following link:-http://www.asp.net/entity-framework/tutorials/ Implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-applicationHowever, I DoNot has options forContext. Set or context. Entry, which Ships with EF4.1- isThere some other how to doing it? Please see problem codeinchBold below:-usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Data;//For entitystateusingSystem.Data.Entity;usingSystem.Linq.Expressions;//For Expression commandusingTaspomark4.models;namespacetaspomark4.models{ Public classGenericrepository<tentity>whereTEntity:class { Internaltasentities context; InternalDbset<tentity>DbSet; Publicgenericrepository (tasentities context) { This. Context =context; This. DbSet = Context. Set<tentity>(); } PublicIenumerable<tentity>Get (Expression<func<tentity,BOOL>> filter =NULL, Func<iqueryable<tentity>, iorderedqueryable<tentity>> =NULL, stringIncludeproperties ="") {IQueryable<TEntity> query =DbSet; if(Filter! =NULL) {Query=query. Where (filter); } foreach(varIncludepropertyinchIncludeproperties.split (New Char[] {','}, Stringsplitoptions.removeemptyentries)) {query=query. Include (Includeproperty); } if(!! =NULL) { return(query). ToList (); } Else { returnquery. ToList (); } } Public VirtualTEntity GetByID (ObjectID) {returndbset.find (ID); } Public Virtual voidInsert (TEntity entity) {Dbset.add (entity); } Public Virtual voidDelete (ObjectID) {TEntity entitytodelete=dbset.find (ID); Delete (Entitytodelete); } Public Virtual voidDelete (TEntity entitytodelete) {*//below Context.entry does not exist**//if (context. Entry (Entitytodelete). state = = entitystate.detached) **//if (context. Objectstatemanager.getobjectstateentry (entitytodelete) = = entitystate.detached) **//{* Dbset.attach (entitytodelete); //} Dbset.remove (Entitytodelete); } Public Virtual voidUpdate (TEntity entitytoupdate) {Dbset.attach (entitytoupdate); *//context. Entry does not exist**//context. Entry (entitytoupdate). State = entitystate.modified;*//GR skinning a cat (06/05/2011)context. Objectstatemanager.changeobjectstate (Entitytoupdate, entitystate.modified); }}}as you can see directly above, I had attempted to use context. Objectstatemanager.changeobjectstate- is ThisCorrect?Many thanksinchAdvance forsomeone can provide,graemeedited by:user4487499 on .-may- . Geneva: $edited by:user4487499 on .-may- . Geneva: $edited by:user4487499 on .-may- . Geneva: +
EF how to use context. Set and context. Entry, which ships with EF4.1?