I have an enum called Permissions. Permissions may be assigned to a user, or roles may be assigned permissions, and a role may be granted to a user.
The user and role have a property similar to this:
public virtual IList<Permission> Permissions { get; set; }
I want to use an enumeration for Permissions, so in my code I can do things like
public static bool UserHasPermission(Permission.DeleteUser)
Now I have about 50 different permissions in my enumeration. It would be nice if I didn't have to populate the mirrors dataset in the database. My listing is as follows:
public enum Permission
{
[StringValue("View Users")]
ViewUser = 1,
[StringValue("Add User")]
AddUser = 2,
[StringValue("Edit User")]
EditUser = 3,
[StringValue("Delete User")]
DeleteUser = 4
...
}
I currently have a permissions table which is PermissionId (int) and PermissionName (varchar (50)).
Here are my role side tables. The user side is exactly the same as the permissions:
CREATE TABLE dbo.Roles
(
RoleId int IDENTITY(2,1) NOT NULL,
RoleName varchar (50) NOT NULL,
CONSTRAINT PK_Roles PRIMARY KEY CLUSTERED (RoleId)
)
CREATE TABLE dbo.RolePermissions
(
RolePermissionId int IDENTITY(1,1) NOT NULL,
RoleId int NOT NULL,
PermissionId int NOT NULL,
CONSTRAINT PK_RolePermissions PRIMARY KEY CLUSTERED (RolePermissionId),
CONSTRAINT FK_RolePermissions_Roles FOREIGN KEY (RoleId) REFERENCES Roles(RoleId),
CONSTRAINT U_RolePermissions UNIQUE(RoleId, PermissionId)
)
tble , , , id RolePermissions, Permissions .
CREATE TABLE dbo.Permissions
(
PermissionId int NOT NULL,
PermissionName varchar (50) NOT NULL,
CONSTRAINT PK_Permissions PRIMARY KEY CLUSTERED (PermissionId)
)
- ?
- , Permissions, UserPermissions RolePermissions PermissionId int enum?
- Permissions, , nhibernate Permissions ?
, , - :
HasManyToMany(x => x.Permissions)
.WithParentKeyColumn("RoleId")
.WithChildKeyColumn("PermissionId")
.WithTableName("RolePermissions")
.LazyLoad()
.Cascade.All();
, :
RolePermissions unmapped : GotRoleplay.Core.Domain.Model.Permission
? fluentnhibernate, , ?