Recently in the group (134710707) of friends are discussing ABP source code, I have recently learned the contents of the record, but also share to everyone, I hope that the ABP source of friends have some help.
The introduction of the ABP of the multi-language, the main introduction of the rights of the database design, with EntityFramework has been a period of time, based on the ABP such a design or the first time to see, specific application Scenarios 1:N,ABP permissions design, menu permissions can be configured to the role of can also be assigned directly to the user.
Another application scenario can also be the order system: the customer can through the order inquiry to the customer all order details, the order details and the customer has no relationship, if you want to directly view the customer's order details, can also be designed in this way, the specific design method is as follows
DbContext Design Class (Isolated demo)
Public classTest:dbcontext {//your context has been configured to be from your application's configuration file (app. config or Web. config)//Use the "Test" connection string. By default, this connection string is for the LocalDb instance on your//the "Study.EF.Test" database. // //if you want to target other databases and/or database providers, modify the "Test" in the application configuration file//The connection string. PublicTest ():Base("name=test") { } //add DbSet for each entity type that you want to include in the model. about configuring and using the Code first model//For more information, seehttp://go.microsoft.com/fwlink/?LinkId=390109. Public Virtual dbset<permission> Permission {get; set;} Public virtual dbset<userpermission> UserPermission {get; set;} Public virtual dbset<rolepermission> rolepermission {get; set;} Public VirtualDbset<user> User {Get;Set; } Public VirtualDbset<role> Role {Get;Set; } } Public classPermission { Public intId {Get;Set; } Public stringName {Get;Set; } } Public classuserpermission:permission { Public intUserId {Get;Set; } //user-based permissions } Public classrolepermission:permission { Public intRoleid {Get;Set; } //Role-based permissions } Public classUser {
Public User ()
{
Permissions = new hashset<userpermission> ();
}
Public intId {Get;Set; } Public stringName {Get;Set; } [ForeignKey ("UserId")] Public VirtualIcollection<userpermission> Permissions {Get;Set; } //user-based permissions list } Public classRole {
Public Role ()
{
Permissions = new hashset<rolepermission> ();
}
Public int Get Set ; } Public string Get Set ; } [ForeignKey ("roleid")] Public Virtual Get Set ; } //Role-based permissions list }
The generated database is 3 tables, not 5 tables, such as
EF Add Data method:
using(varText =NewTest ()) { varU =NewUser (); U.name="Test"; varup =NewUserPermission (); Up. Name="UserPermission"; U.permissions.add (UP); //Add User Rightstext. User.add (U); varRole =NewRole (); Role. Name="roletest"; varRP =Newrolepermission (); Rp. Name="rolepermission"; Role. Permissions.add (RP); //Add role Permissionstext. Role.add (role); Text. SaveChanges (); }
Execution results, field discriminator is the field generated by EF itself, used to differentiate the data source
The user, Role, permission database design of ABP (another way to use entityframework inheritance)