asp.net MVC Rights Management (II) entity model design

Source: Internet
Author: User
Tags bool log sort

The previous article has written about the basic development of the project and the project used some things, this article began to design the entity model, well, nonsense not much to say.

Entity model base Class

Because each model entity needs to have a number, state these basic things, in order to adhere to the MVC "do not repeat themselves" principle, the common thing is written to a public class, previously developed I used to use the increment of int as the primary key, this time I intend to try the GUID as the primary key number of the database, If there is no understanding of the place, we hasten to point out AH ~ ~

There's a code for the truth:

<summary>
    ///model base class
    ///</summary> public
   class baseentity
    {
        private string ID;
        [Key]
        [Display (Name = "PRIMARY key")]
        public string Id
        {
            get
            {
                if (Id = = null)
                {return
                    guid.newguid (). ToString ();
    
                }
                else
                {return
                    ID;
                }
    
            }
            Set
            {
                id = value;
    
            }
        }
    
    
    
        [Display (Name = "status")]
        [Required (errormessage = "Status cannot be empty!) )] The public
        bool is Enabled {get; Set }
    }

Second, the Entity model

Tbuser "User Model"

Tbrole "Role Model"

Tbmodule "System Module Model"

Tbaction "System Behavior Model"

Tbactionlog "Behavioral Log Model"

Iii. the relationship between models

User model corresponds to multiple role models, the role model corresponds to multiple user models, that is, a user can belong to multiple roles, a role has n multiple users;

The role model corresponds to multiple system models, which means that a role has multiple system module permissions.

System behavior model and system behavior log model is just a log, we look at the affirmation am hesitant understand, I will not ink.

Implementation of the common class of data access interface layer and data access implementation layer

Ibasedao data Access interface layer, the code is as follows:

<summary>///additions and deletions to the public interface, this interface defines generic additions and deletions to check///</summary>///<typeparam name= "T" > Entity </typ Eparam> public interface Ibasedao<t> {#region Query Common implementation (where query based on lambda expression)///<summ Ary>///obtain///for all entity///</summary> <param name= &GT;LAMBDA "exp" WHERE&LT;/PARAM&G conditions
        T
        <returns></returns> ienumerable<t> getallentities (func<t, bool> exp); <summary>///Calculation total number (paging)///</summary>///<param name= "exp" >lambda conditions wher
    
        e</param>///<returns></returns> int getentitiescount (func<t, bool> exp); <summary>///page query (LINQ paging)///</summary>///<param name= "PageNumber" > Current page </param>///<param name= "pageSize" > Paging size </param>///<param name= "Ordername" &G T;lambda Sort Name </param>///<param name= "SortOrder" > Sort, Ascending or descending </param>///<param name= "exp" >lambda query criteria where </param>///<returns></returns> ienumerable<t> getentitiesforpaging (int Pagenumbe
    
        R, int pageSize, func<t, string> ordername, String sortOrder, Func<t, bool> exp); <summary>///Find individual entities///</summary>///<param name= "exp" &GT;LAMBDA query criteria based on criteria wher
    
    
        e</param>///<returns></returns> T getentity (func<t, bool> exp); #endregion #region Tim///<summary>///Insert Entity/// ;/summary>///<param name= "entity" ></param>///<returns></returns> bo
    
        OL Insert (T entity);
        <summary>///Update entity///</summary>///<param name= "entity" ></param><returns></returns> BOOL Update (T entity);
        <summary>///Delete entity///</summary>///<param name= "entity" ></param>
    
    
        <returns></returns> BOOL Delete (T entity); #endregion}

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/

Related Article

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.