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= >LAMBDA "exp" WHERE</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" >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/