EF how to use context. Set and context. Entry, which ships with EF4.1?

Source: Internet
Author: User

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&gt, 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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.