EF General Class

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Data.Entity;usingSystem.Data.Entity.Infrastructure;usingSystem.Linq;usingSystem.Runtime.Remoting.Contexts;usingSystem.Text;usingSystem.Threading.Tasks;namespacedomain.infrastructure{ Public classBaserepository<t>whereT:class    {        protectedCcdbcontext Context =ccdbcontext.current;  Public VirtualIqueryable<t>GetAll () {varls = context.set<t>(); returnls; }         Public VirtualIqueryable<t> GetAll (stringincludes) {            if(!string. Isnullorwhitespace (includes)) {string[] ins = includes. Split (','); Dbquery<T> query = context.set<t>(); foreach(stringSinchins) {Query=query.                Include (s); }                returnquery; }            returnContext.set<t>(); }         Public voidAdd (T entity) {Context.set<T>().            ADD (entity);        Context.savechanges (); }         Public Virtual voidUpdate (T entity) {varEntry =Context.entry (entity); Context.set<T>().            Attach (entity); Entry. State=entitystate.modified;        Context.savechanges (); }         Public VirtualT Get (intID) {returnContext.set<t> (). Find (New Object[] {ID}); }         PublicT Get (Object[] IDs) {            returnContext.set<t>().        Find (IDS); }         Public Virtual BOOLDel (intID) {varentity = context.set<t> (). Find (New Object[] {ID}); if(Entity = =NULL)                return false; Context.set<T>().            Remove (entity);            Context.savechanges (); return true; }         Public Virtual BOOLDel (int[] IDs) {            if(ids = =NULL|| Ids. Length <=0)            {                return false; }            varChanged =false; foreach(varIdinchIDs) {                varentity =Get (ID); if(Entity! =NULL) {Context.set<T>().                    Remove (entity); Changed=true; }            }            if(changed) context.savechanges (); returnchanged; }    }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Data.Entity;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;usingsystem.web;usingDomain.Course.Entry;usingDomain.User.Entry;namespacedomain.infrastructure{ Public classCcdbcontext:dbcontext { PublicCcdbcontext ():Base("Name=conn")        {        }        Private StaticThreadlocal<ccdbcontext>_threadlocal; Private StaticCcdbcontext _current;  Public StaticCcdbcontext Current {Get            {                if(HttpContext.Current = =NULL)                {                    //Non-web environment                    if(_threadlocal = =NULL) {_threadlocal=NewThreadlocal<ccdbcontext> (() =NewCcdbcontext ()); } _current=_threadlocal.value; return_threadlocal.value; }                Else                {                    varcached = httpcontext.current.items["_ccdbcontext"]; if(Cached! =NULL&& Cached isCcdbcontext) {_current= Cached asCcdbcontext; return_current; }                    Else                    {                        varContext =NewCcdbcontext (); httpcontext.current.items["_ccdbcontext"] =context; _current=context; returncontext; }                }            }        }         Public Static voiddisposecurrent () {if(_current! =NULL) _current.        Dispose (); }        #regionAll instances PublicDbset<word> Words {Get;Set; }  PublicDbset<wordtranslation> Wordtranslations {Get;Set; }  PublicDbset<language> Languages {Get;Set; }  PublicDbset<catalog> Catalogs {Get;Set; }  PublicDbset<catalogname> CatalogNames {Get;Set; }  PublicDbset<term> Terms {Get;Set; }  PublicDbset<termtranslation> Termtranslations {Get;Set; }  Publicdbset<lesson> Lessons {Get;Set; }  PublicDbset<lessonword> Lessonwords {Get;Set; }  PublicDbset<relevantterm> Relevantterms {Get;Set; }  PublicDbset<domain.user.entry.user> Users {Get;Set; }  PublicDbset<group> Groups {Get;Set; }  PublicDbset<grouptranslation> Grouptranslation {Get;Set; }  PublicDbset<termgroup> Termgroup {Get;Set; }  PublicDbset<relevantgroup> relevantgroups {Get;Set; }  PublicDbset<derivations> Derivations {Get;Set; }  PublicDbset<relatedword> Relatedword {Get;Set; }  PublicDbset<role> Role {Get;Set; }  PublicDbset<wordsh> WORDSH {Get;Set; }  PublicDbset<shinfo> Shinfo {Get;Set; }  PublicDbset<part> Part {Get;Set; }  PublicDbset<radical> Radical {Get;Set; }  PublicDbset<wordpart> Wordpart {Get;Set; } #endregion    }}

EF General Class

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.