Construction of ASP.net mvc4+ef5+easyui+unity2.x injection background Management system (5)

Source: Internet
Author: User

EF additions and deletions by bad code

We created a series of solutions in the previous session, and we looked at the relationship between layers through an example.

We separated the controllers from the BLL layer and the DAL layer.

BLL focus on the business process

DAL focuses on data access layer processing

and controller with a clear view of the interaction

We have added an entity to EF in the last lecture syssample

Let's create the IDAL,DAL,IBLL,BLL code below.

Using App.models;
Using System.Linq;
        Namespace App.idal {public interface isyssamplerepository {///<summary>///get list </summary>///<param name= "db" > Database context </param>///<returns> data list &LT;/RETURNS&G
        T
        Iqueryable<syssample> getlist (Dbcontainer db); <summary>///Create an entity///</summary>///<param name= "entity" > Entity </param&gt
        ;
        int Create (syssample entity); <summary>///Delete an entity///</summary>///<param name= "entity" > Primary key id</param&
        Gt
           
        int Delete (string id); <summary>///Modify an entity///</summary>///<param name= "entity" > Entity </param&gt
        ;
        int Edit (syssample entity);
        <summary>///get an entity///</summary>///<param name= "id" >id</param> /// <returns> entity </returns> syssample GetByID (string id);
    <summary>///to determine whether an entity exists///</summary> bool Isexist (string ID); }} ISysSampleRepository.cs
Using System;
Using System.Linq;
Using App.idal;
Using App.models;
    
Using System.Data; Namespace App.dal {public class syssamplerepository:isyssamplerepository, IDisposable {///<summary >///Get list///</summary>///<param name= "db" > Database context </param>///
            ;returns> Data List </returns> public iqueryable<syssample> getlist (Dbcontainer db) { iqueryable<syssample> list = db.
            Syssample.asqueryable ();
        return list; ///<summary>///Create an entity///</summary>///<param name= "db" > Database context
            ;/param>///<param name= "entity" > Entity </param> public int Create (syssample entity) { using (Dbcontainer db = new Dbcontainer ()) {db.
                Syssample.addobject (entity); Return DB.
            SaveChanges (); }}///<summAry>///Delete an entity///</summary>///<param name= "db" > Database context </param>// /<param Name= "entity" > Primary key id</param> public int Delete (string id) {using (Dbcontai NER db = new Dbcontainer ()) {syssample entity = db.
                Syssample.singleordefault (a => a.id = Id); if (entity!= null) {db.
                Syssample.deleteobject (entity); Return DB.
            SaveChanges (); }///<summary>///modifies an entity///</summary>///<param name= "D B "> Database context </param>///<param name=" entity "> Entity </param> public int Edit (Syssample entit Y) {using (Dbcontainer db = new Dbcontainer ()) {db.
                Syssample.attach (entity); Db. Objectstatemanager.changeobjectstaTE (entity, entitystate.modified); Return DB.
            SaveChanges (); }///<summary>///obtains an entity///</summary>///<param name= "id"
            ;id</param>///<returns> entity </returns> public syssample GetByID (string id) { using (Dbcontainer db = new Dbcontainer ()) {return db.
            Syssample.singleordefault (a => a.id = Id); }///<summary>///to determine if an entity exists///</summary>///<param name= "id 
        ">id</param>///<returns> exists true or false</returns> public bool Isexist (string ID) {using (Dbcontainer db = new Dbcontainer ()) {syssample entity = GetByID
                (ID);
                if (entity!= null) return true;
            return false; }} public void DispOSE () {}}}
    
 

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.